2 * Copyright 2009, Sine Nomine Associates and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 /* only build on platforms that have SysV IPC support; i.e., when we
22 #include "audit-api.h"
24 /* solaris default is 2048 */
27 /* message queue size will be increased to this value
28 if not already bigger */
29 #define MSGMNB (2*1024*1024)
31 static struct my_msgbuf
{
38 static struct mqaudit_stats
{
49 /* +1 to send the trailing '\0' in the message too so the
50 receiver doesn't need to bother with it */
51 if (msgsnd(mqid
, &msgbuffer
, strlen(msgbuffer
.mtext
)+1, IPC_NOWAIT
) == -1) {
53 } else if (truncated
) {
54 myauditstats
.truncated
++;
57 msgbuffer
.mtext
[0] = 0;
62 append_msg(const char *format
, ...)
67 size
= MAXMSG
- strlen(msgbuffer
.mtext
);
69 va_start(vaList
, format
);
70 printed
= vsnprintf(&msgbuffer
.mtext
[strlen(msgbuffer
.mtext
)], size
, format
, vaList
);
73 /* A return value of size or more means that the output was truncated.
74 If an output error is encountered, a negative value is returned. */
75 if (size
<= printed
|| printed
== -1) {
81 open_file(const char *fileName
)
84 struct msqid_ds msqdesc
;
86 msgbuffer
.mtext
[0] = 0;
91 myauditstats
.lost
= 0;
92 myauditstats
.truncated
= 0;
94 /* try to create file for ftok if it doesn't already exist */
95 tempfd
= open(fileName
, O_WRONLY
| O_CREAT
| O_EXCL
, S_IRUSR
| S_IWUSR
);
99 mqid
= msgget(ftok(fileName
, 1), S_IRUSR
| S_IWUSR
| IPC_CREAT
);
101 printf("Warning: auditlog message queue %s cannot be opened.\n", fileName
);
105 /* increase message queue size */
106 msgctl(mqid
, IPC_STAT
, &msqdesc
);
107 if (msqdesc
.msg_qbytes
< MSGMNB
) {
108 msqdesc
.msg_qbytes
= MSGMNB
;
109 msgctl(mqid
, IPC_SET
, &msqdesc
);
116 print_interface_stats(FILE *out
)
118 fprintf(out
, "audit statistics: %ld messages total, %ld truncated, %ld lost\n",
119 myauditstats
.all
, myauditstats
.truncated
, myauditstats
.lost
);
122 const struct osi_audit_ops audit_sysvmq_ops
= {
126 &print_interface_stats
,
129 #endif /* HAVE_SYS_IPC_H */