Server for Information Technologies ������ ��������������
������� �������������� ����������
(095) 932-9212, 932-9213, 939-0783
E-mail: [email protected]
������ �������� ����(!) ������������� ���������� CIT Forum CD-ROM

LOG(7)

��������
log - ��������� ��� ����������� ������ � ����������� ������� ���������������

��������
������� log ������������ ��������� ��� ��������� ����������� ������ � ����������� ������� ��������������� [��. strerr(1M), strace(1M)]. Log ������������� ��� ��������� ����������: ��������� ������ ������� �� ����, ����� ������� �������� � ������ ��������������� �������� ��������� ��� �����������, � ����� ����� ������ ��� ���������� ������ ioctl(2) ��� �������������� �� ���������� ������ � ���������� ����������� � �����������, � ����� ��� ���������, ������� ��������� �������������� ���� ����������� ���������.

����� ������� �� ����
��������� ���������� ��� ����������� ����� ������ �� ���� ������� strlog:

#include <sys/stropts.h>
#include <sys/strlog.h>
#include <sys/log.h>

strlog (mid, sid, level, flags, fmt, arg1, ...)
short mid, sid;
char level;
unsigned short flags;
char *fmt;
unsigned int arg1;

�������� mid - ��� ������������� ������ ��� ������ ��� ��������, ����������� ��������� ��� �����������. �������� sid ������ �������������� ���������� �������� �������������, ������ ������������ ��� ������������� �������� ���������� � ��������. �������� level - ��� ������� ���������� �����������, ������ ����������� ������������� ����������� (�������� ��������� � ������ �����������). �������� flags ������������ ����� ���������� ��������� ��������:

SL_ERROR
��������� ����������������, ��� ������.
SL_TRACE
�������������� ���������.
SL_FATAL
��������� ������.
SL_NOTIFY
������� ��������� ���������� �������������� ����� mail(1).

�������� fmt - ��� ������� ��������, �������� ������ � ����� printf(3S), �� ������������� %s, %e, %E, %g � %G �� ��������������. ���������� �������������� �������� ���������� (arg1, ...) ���������� ��������� NLOGARGS (� ��������� ������ ��� ����� 3).

��������� ������������
������ � ���������� log �������������� ����� �������� ���������� /dev/log ����� ������� clone(7). ������ �������� ���������� /dev/log �������� ��������� ����� � �������� log. ����� �������� ��������� �� �������� log, ������� ������ ���������� ������� � ������� ������� I_STR ���������� ������ ioctl(2) � ����� ������� ������������ ��������� �� ������� ��� �������������� ���������, ������ � �������� �������� ��������� ��� ���������� ������ ioctl ����� ��������� ���� struct strioctl.

struct strioctl {                               
  int  ic_cmd;     /* ������� */            
  int  ic_timout;  /* ������� */            
  int  ic_len;     /* ����� ������ */       
  char *ic_dp;     /* ��������� �� ������ */
};                                              

��� ����, ����� ������������ ��������� �� �������, ���������� � ���� ic_cmd ������������ ��������� �������� ��������� I_ERRLOG, � ���� ic_len - 0, � � ���� ic_dp NULL. ��� ����, ����� ������������ �������������� ���������, ���������� � ���� ic_cmd ������������ ��������� �������� ��������� I_TRCLOG, � ���� ic_dp ������ ����� ������� �������� ���� struct trace_ids, � � ���� ic_len - ����� ����� ������� � ������.

struct trace_ids {
  short ti_mid;  
  short ti_sid;  
  char  ti_level;
};                

������ ������� ������� ������ �������� �������������� ������, �������������� ���������� � ������ ����������� ���������. ������� strlog ����� �������� ������ �� ���������, ��� ������� �������� ��������������� ������ � ���������� ��������� � ���������� � �������, � �������� ������ �� ����������� ���������� � �������. ������� �������� -1 � ����� �� ����� ti_mid, ti_sid, ti_level �������� ���������� ��������������� �����������.

� ������ ������ ������� ������ ���� ������� ����� ������������ ��������� �� ������� � ������ ���� ������� ����� ������������ �������������� ���������.

����� ����, ��� ������� � ������� ���������� ������ ioctl �� ����, ��� �� ����� ������������ ���������, log �������� �������� ��� ��� ���������, ��������������� ��������� ������������. ��� ��������� ����� �������� � ������� ���������� ������ getmsg(2).

����������� ������� ��������� �������� ��������� ���� struct log_ctl, � ������� ������� �������������� ������ � ����������, �������, �����, ����� ������� ��������� � ������ ����� �� ��������� �������� �������, �� �� ����� � �������� �� 1 ������ 1970 ���� � ���������� �����.

struct log_ctl {                                      
  short mid;                                       
  short sid;                                       
  char  level;                                     
  short flags;                                     
  long  ltime;  /* ����� � ������ �� �������� */
  long  ttime;  /* ����� � �������� �� 1.01.1970 */
  long  seq_no; /* ���������� ����� */             
};                                                    

����� � �������� �� 1 ������ 1970 ���� ��������� ������, ����� ���� ������� ���������, � ����� � ������ ��������� �������� ���������� �� ���������� ����� �����������. �������������� ��� ���� ���������������� �������: ��� ��������� �� ������� � ��� �������������� ���������. �������� � ���������� ������� ��������� ���������� ���� ������ ��������� ��� �������� ������� ������������� �������.

������� ������ ��������� �������� ������ - ������� ��������, �������������� �����, �� ������� ������� ����������� �� ������� ����� NLOGARGS ����, �������������� ��������� ��� ����� �������.

����� �������, ���� �� ���������� ������������ ������ ��� �����������, ����� �������� ��������� �������� ��������� �������� log. ��� ���� � ����������� ������� ��������� � ��������� log_ctl ����� ������ ������ ���� level � flags, ��������� ���� ����� ��������� �� ��������� ��������� ��� ������� log. ������� ������ ������ ��������� ������, �� �������, ����������� �� ������� �����, ����� ��������� �� NLOGARGS ����, �������������� ���������.

������� ������� ������ I_ERRLOG ��� I_TRCLOG, ����� ��� ���������� �������-���������� ���� �� ����, �������� � ������ � ����� ENXIO. �� �� ������ ENXIO ��������, ���� ��� ������� I_TRCLOG �� ����� ������ �������� trace_ids, � ����� ���� ������ �������� � ������� I_STR �����������. ��������� ��� �������� log �� ��������� ������������, ������� ����� ������������ ���������, ������������ ��� ��������� �� �������.

�������

  1. ������ ������� �� ��������� ��������� �� �������:
         struct strioctl ioc;
         
         ic.ic_cmd = IERRLOG;
         ic.ic_timeout = 0;  /* ������� �� ��������� (15 �) */
         ic.ic_len = 0;
         ic.ic_dp = NULL;
         
         ioctl (log, I_STR, &ioc);
    
  2. ������ ������� �� ��������� �������������� ���������:
         struct strioctl ioc;
         struct trace_ids tid [2];
         
         tid[0].ti_mid = 2;
         tid[0].ti_sid = 0;
         tid[0].ti_level = 1;
         
         tid[1].ti_mid = 1002;
         tid[1].ti_sid = -1;     /* ����� */
         tid[1].ti_level = -1;   /* ����� */
         
         ic.ic_cmd = ITRCLOG;
         ic.ic_timeout = 0;
         ic.ic_len = 2 * sizeof (struct trace_ids);
         ic.ic_dp = (char *) tid;
         
         ioctl (log, I_STR, &ioc);
    
  3. ������ �������� ��������� �������� log (��� ����������):
         struct strbuf ctl, dat;
         struct log_ctl lc;
         char *message = "I am waiting for you";
         
         ctl.len = ctl.maxlen = sizeof (lc);
         ctl.buf = (char *) &lc;
         
         dat.len = dat.maxlen = strlen (message) + 1;
         dat.buf = message;
         
         lc.level = 0;
         lc.flags = SL_ERROR | SL_NOTIFY;
         
         putmsg (log, &ctl, &dat, 0);
    

�����

/dev/log
<sys/stropts.h>
<sys/log.h>
<sys/strlog.h>

��. �����
strace(1M), strerr(1M), clone(7).
intro(2), getmsg(2), ioctl(2), putmsg(2) � ����������� ������������.
Comments: [email protected]
Designed by Andrey Novikov
Copyright © CIT