]>
git.ipfire.org Git - thirdparty/systemd.git/blob - udeveventrecorder.c
6 * Copyright (C) 2004, 2005 Olaf Hering <olh@suse.de>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation version 2 of the License.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <sys/types.h>
33 #include "udev_version.h"
34 #include "udev_utils.h"
43 void log_message (int priority
, const char *format
, ...)
50 va_start(args
, format
);
51 vsyslog(priority
, format
, args
);
56 int main(int argc
, char **argv
, char **envp
)
65 if (stat("/events", &sb
) || !(S_ISDIR(sb
.st_mode
)))
68 env
= getenv("UDEV_LOG");
70 log
= log_priority(env
);
72 logging_init("udeveventrecorder");
73 dbg("version %s", UDEV_VERSION
);
78 if (!(buf
&& a
&& argv
[1]))
81 seq
= strtoul(p
, NULL
, 0);
85 snprintf(buf
, FNSIZE
, "/events/debug.%05lu.%s.%s.%u", seq
, argv
[1], a
? a
: "", getpid());
86 if ((fd
= open(buf
, O_CREAT
| O_WRONLY
| O_TRUNC
, 0644)) < 0) {
87 err("error creating '%s'", buf
);
93 buf
+= snprintf(buf
, p
+ BUFSIZE
- buf
, "set --");
94 for (i
= 1; i
< argc
; ++i
) {
95 buf
+= snprintf(buf
, p
+ BUFSIZE
- buf
, " %s", argv
[i
]);
96 if (buf
> p
+ BUFSIZE
)
99 buf
+= snprintf(buf
, p
+ BUFSIZE
- buf
, "\n");
100 if (buf
> p
+ BUFSIZE
)
104 t
= memchr(*ep
, '=', strlen(*ep
));
108 buf
+= snprintf(buf
, p
+ BUFSIZE
- buf
, "%s='%s'\n", *ep
, t
);
113 if (buf
> p
+ BUFSIZE
)
119 write(fd
, buf
, strlen(buf
));
125 fprintf(stderr
, "record enviroment to /events, to be called from udev context\n");