免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1779 | 回复: 1

帮忙分析一下AIX下的一个API和我的程序 [复制链接]

论坛徽章:
0
发表于 2007-07-29 00:16 |显示全部楼层
errlog_open Subroutine (摘自AIX5.2 Technical Reference: Base Operating System and Extensions, Volume 1)

Purpose
Opens an error log and returns a handle for use with other liberrlog.a functions.

Syntax
library liberrlog.a
#include <fcntl.h>
#include <sys/errlog.h>
int errlog_open(path, mode, magic, handle)
char *path; int mode; unsigned int magic;
errlog_handle_t *handle;

Description

The error log specified by the path argument will be opened using mode. The handle pointed to by the handle parameter must be used with subsequent operations.

Parameters

The path parameter specifies the path to the log file to be opened. If path is NULL, the default errlog file will be opened. The valid values for mode are the same as they are for the open system subroutine. They can be found in the fcntl.h files. The magic argument takes the LE_MAGIC value, indicating which version of the errlog_entry_t structure this application was compiled with.

Return Values
Upon successful completion, the errlog_open subroutine returns a 0 and sets the memory pointed to by handle to a handle used by subsequent liberrlog operations.

Upon error, the errlog_open subroutine returns one of the following:
LE_ERR_INVARG     A parameter error was detected.
LE_ERR_NOFILE     The log file does not exist.
LE_ERR_NOMEM      Memory could not be allocated.
LE_ERR_IO         An i/o error occurred.
LE_ERR_INVFILE    The file is not a valid error log.


我在开发一个监控AIX system error log的程序,虽然用shell更简单一些,但我必须用C来实现它。上面这个API就是用来打开system error log的系统调用,在程序中这个系统调用返回值为1,请问我如何判断错误返回类型是:LE_ERR_INVARG  LE_ERR_NOFILE LE_ERR_NOMEM  LE_ERR_IO  LE_ERR_INVFILE中的哪一种?

以下是我的程序代码及运行输出,请帮忙查看我的程序和方法是否有错误?(共两个问题)
asm@zhguowen_sv:/asmdev/asm$vi errlog_op.c
"errlog_op.c" 30 lines, 509 characters
#include <stdio.h>
#include <fcntl.h>
#include <sys/errlog.h>
#include <libperfstat.h>

int mode;
unsigned int magic;
errlog_handle_t hl;

main()
{
   mode=0;
   magic=LE_MAGIC;
   int rc,ac;
   char path[]="/var/adm/ras/errlog";
   int er_dir=LE_REVERSE;
   rc=errlog_open(path,mode,magic,hl);
   sleep(1);
   if (rc==0) { printf("\nopen errlog sucessful!\n"); }
   else
   {
       printf("\nopen errlog failed!rc=%i\n",rc);

   }

   ac=errlog_set_direction(hl,er_dir);
   printf("\n ac= %i",ac);

}
~~
:q!
asm@zhguowen_sv:/asmdev/asm$cc -lperfstat errlog_op.c /usr/lib/liberrlog.a
asm@zhguowen_sv:/asmdev/asm$./a.out

open errlog failed!rc=1

ac= 1

论坛徽章:
0
发表于 2007-07-29 09:30 |显示全部楼层

  1. rc=errlog_open(path,mode,magic,hl);
  2. switch(rc){
  3.   0:
  4.   LE_ERR_INVARG:...
  5.   LE_ERR_NOFILE:...
  6.   LE_ERR_NOMEM:...
  7.   LE_ERR_IO:...
  8.   LE_ERR_INVFILE:...
  9. }
复制代码

明白了么
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP