]>
git.proxmox.com Git - mirror_smartmontools-debian.git/blob - os_win32/syslogevt.c
08019fec17fe8dcf0ec9cf75d7dcbe5b150f911d
4 * Home page of code is: http://smartmontools.sourceforge.net
6 * Copyright (C) 2004-10 Christian Franke <smartmontools-support@lists.sourceforge.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * You should have received a copy of the GNU General Public License
14 * (for example COPYING); if not, write to the Free
15 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 static char rcsid
[] = "$Id: syslogevt.c 3257 2011-02-14 22:19:42Z manfred99 $";
25 #define WIN32_LEAN_AND_MEAN
28 #include "syslogevt.h"
29 // Compile time check for Message Ids, see also syslog_win32.cpp
30 typedef assert_msg_syslog
[MSG_SYSLOG
== 0 ? 1 : -1];
31 typedef assert_msg_syslog_01
[MSG_SYSLOG_01
== 1 ? 1 : -1];
32 typedef assert_msg_syslog_10
[MSG_SYSLOG_10
== 10 ? 1 : -1];
38 "syslogevt $Revision: 3257 $ Copyright (C) 2004-10 Christian Franke\n"
39 "Home page is http://smartmontools.sourceforge.net/\n"
41 "Usage: syslogevt [-ru] name [ident ...]\n"
43 "Creates registry files \"name-r.reg\" and \"name-u.reg\" to (un)register\n"
44 "this program as an event message file for message source(s) \"ident\".\n"
45 "If \"ident\" is ommited, \"name\" is used. Options:\n"
47 " -r run \"regedit name-r.reg\" after creating files\n"
48 " -u run \"regedit name-u.reg\" after creating files\n"
52 "syslogevt smartd (Create smartd-r.reg and smartd-u.reg)\n"
53 "regedit smartd-r.reg (Register syslogevt.exe for smartd messages)\n"
55 "syslogevt -r smartd (Same as above in one step)\n"
57 "regedit smartd-u.reg (Undo the registration)\n"
59 "CAUTION: A registry entry of an existing event source with the same \"ident\"\n"
60 " will be overwritten by regedit without notice."
65 main(int argc
, char ** argv
)
68 char name1
[30+1], name2
[30+1], mypath
[MAX_PATH
+1];
77 if (!strcmp(argv
[a1
], "-r")) {
80 else if (!strcmp(argv
[a1
], "-u")) {
84 for (ai
= a1
; ai
< argc
; ai
++) {
86 if (!(ident
[0] && strlen(ident
) < sizeof(name1
)-10
87 && strcspn(ident
, "-.:/\\") == strlen(ident
) )) {
92 if (!GetModuleFileName(NULL
, mypath
, sizeof(mypath
)-1)) {
93 fputs("GetModuleFileName failed\n", stderr
);
98 strcpy(name1
, ident
); strcat(name1
, "-r.reg");
99 strcpy(name2
, ident
); strcat(name2
, "-u.reg");
101 if (!(f1
= fopen(name1
, "w"))) {
102 perror(name1
); return 1;
104 if (!(f2
= fopen(name2
, "w"))) {
105 perror(name2
); fclose(f1
); unlink(name1
); return 1;
108 fputs("REGEDIT4\n\n", f1
);
109 fputs("REGEDIT4\n\n", f2
);
111 for (ai
= (argc
> a1
+1 ? a1
+1 : a1
); ai
< argc
; ai
++) {
114 fputs("[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Eventlog\\Application\\", f1
);
115 fputs(ident
, f1
); fputs("]\n\"EventMessageFile\"=\"", f1
);
116 for (i
= 0; mypath
[i
]; i
++) {
117 if (mypath
[i
] == '\\')
119 fputc(mypath
[i
], f1
);
121 fputs("\"\n\"TypesSupported\"=dword:00000007\n\n", f1
);
123 fputs("[-HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Eventlog\\Application\\", f2
);
124 fputs(ident
, f2
); fputs("]\n\n", f2
);
130 if (GetVersion() & 0x80000000) {
131 puts("Warning: Event log not supported on Win9x/ME\n");
137 if (spawnlp(P_WAIT
, "regedit", "regedit", (regedit
> 0 ? name1
: name2
), (const char *)0) == -1) {
138 fputs("regedit: cannot execute\n", stderr
);
143 fputs("Files generated. Use\n\n regedit ", stdout
);
145 fputs("\nto register event message file, and\n\n regedit ", stdout
);
147 fputs("\nto remove registration later.\n\n"
148 "Do not remove this program when registered.\n", stdout
);