]>
git.proxmox.com Git - mirror_smartmontools-debian.git/blob - os_win32/syslogevt.c
4 * Home page of code is: http://smartmontools.sourceforge.net
6 * Copyright (C) 2004-6 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,v 1.4 2006/04/12 14:54:29 ballen4705 Exp $";
25 #define WIN32_LEAN_AND_MEAN
29 #include "syslogevt.h"
36 "syslogevt $Revision: 1.4 $ Copyright (C) 2004-6 Christian Franke\n"
37 "Home page is http://smartmontools.sourceforge.net/\n"
39 "Usage: syslogevt [-ru] name [ident ...]\n"
41 "Creates registry files \"name-r.reg\" and \"name-u.reg\" to (un)register\n"
42 "this program as an event message file for message source(s) \"ident\".\n"
43 "If \"ident\" is ommited, \"name\" is used. Options:\n"
45 " -r run \"regedit name-r.reg\" after creating files\n"
46 " -u run \"regedit name-u.reg\" after creating files\n"
50 "syslogevt smartd (Create smartd-r.reg and smartd-u.reg)\n"
51 "regedit smartd-r.reg (Register syslogevt.exe for smartd messages)\n"
53 "syslogevt -r smartd (Same as above in one step)\n"
55 "regedit smartd-u.reg (Undo the registration)\n"
57 "CAUTION: A registry entry of an existing event source with the same \"ident\"\n"
58 " will be overwritten by regedit without notice."
63 main(int argc
, char ** argv
)
66 char name1
[30+1], name2
[30+1], mypath
[MAX_PATH
+1];
71 if (!(MSG_SYSLOG
== 0 && MSG_SYSLOG_01
== 1 && MSG_SYSLOG_10
== 10)) {
72 puts("Internal error: MSG_SYSLOG_n != n"); return 1;
81 if (!strcmp(argv
[a1
], "-r")) {
84 else if (!strcmp(argv
[a1
], "-u")) {
88 for (ai
= a1
; ai
< argc
; ai
++) {
90 if (!(ident
[0] && strlen(ident
) < sizeof(name1
)-10
91 && strcspn(ident
, "-.:/\\") == strlen(ident
) )) {
96 if (!GetModuleFileName(NULL
, mypath
, sizeof(mypath
)-1)) {
97 fputs("GetModuleFileName failed\n", stderr
);
102 strcpy(name1
, ident
); strcat(name1
, "-r.reg");
103 strcpy(name2
, ident
); strcat(name2
, "-u.reg");
105 if (!(f1
= fopen(name1
, "w"))) {
106 perror(name1
); return 1;
108 if (!(f2
= fopen(name2
, "w"))) {
109 perror(name2
); unlink(name1
); return 1;
112 fputs("REGEDIT4\n\n", f1
);
113 fputs("REGEDIT4\n\n", f2
);
115 for (ai
= (argc
> a1
+1 ? a1
+1 : a1
); ai
< argc
; ai
++) {
118 fputs("[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Eventlog\\Application\\", f1
);
119 fputs(ident
, f1
); fputs("]\n\"EventMessageFile\"=\"", f1
);
120 for (i
= 0; mypath
[i
]; i
++) {
121 if (mypath
[i
] == '\\')
123 fputc(mypath
[i
], f1
);
125 fputs("\"\n\"TypesSupported\"=dword:00000007\n\n", f1
);
127 fputs("[-HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Eventlog\\Application\\", f2
);
128 fputs(ident
, f2
); fputs("]\n\n", f2
);
134 if (GetVersion() & 0x80000000) {
135 puts("Warning: Event log not supported on Win9x/ME\n");
141 if (spawnlp(P_WAIT
, "regedit", "regedit", (regedit
> 0 ? name1
: name2
), (const char *)0) == -1) {
142 fputs("regedit: cannot execute\n", stderr
);
147 fputs("Files generated. Use\n\n regedit ", stdout
);
149 fputs("\nto register event message file, and\n\n regedit ", stdout
);
151 fputs("\nto remove registration later.\n\n"
152 "Do not remove this program when registered.\n", stdout
);