UPS: apcupsd clean sources
[tomato.git] / release / src / router / apcupsd / doc / techlogs / 2002 / jp09Jan02
blobf15757e4cb9f56b6126ef91d59c08f130197d76a
1 From: Jim Pennino <jimp@specsol.com>
2 To: apcupsd-devel@apcupsd.org
3 Subject: [Apcupsd-devel] HP-UX bug
5 I'm setting up some HP workstations running HP-UX 10.20 with apcupsd and found a 
6 minor bug. This probably applies to HP-UX 11 also, but I don't have access to an 
7 11 machine at the moment to double check.
9 In apc_struct.h there are several declarations (from grep):
11 apc_struct.h:    char configfile[FILENAME_MAX];   /* config filename */
12 apc_struct.h:    char statfile[FILENAME_MAX];     /* status filename */
13 apc_struct.h:    char eventfile[FILENAME_MAX];    /* temp events file */
14 apc_struct.h:    char master_name[FILENAME_MAX];  /**/
15 apc_struct.h:    char lockpath[FILENAME_MAX];     /* BSC, made static -RF */
17 The problem is under HP-UX 10, FILENAME_MAX is defined as 14, i.e. the file name 
18 part of a file path, while most other systems define it as the complete file 
19 path including name. E.g. on Solaris it is 1024.
21 This causes some really bizarre things to happen when you try to run the code 
22 because the code where the definitions are used does not check for overrun of 
23 the defined length. For example:
25 apcconfig.c:    strcpy(ups->configfile, cfgfile);
26 apcconfig.c:    strcpy(ups->lockpath, LOCK_DEFAULT);
27 apcconfig.c:    strcat(ups->lockpath, APC_LOCK_PREFIX);
29 Needless to say /var/spool/locks/LCK..tty0p0 doesn't fit too well into 14 
30 characters...
32 On HP-UX, I fixed this (the definition part, not the check for overrun part) by 
33 simply changing FILENAME_MAX to PATH_MAX.
35 This probably has other implications for ansi/POSIX/whatever systems that may or 
36 may not have a PATH_MAX but will leave the answer to that question to someone 
37 more familiar with the standards.
39 Jim Pennino
41 =======
42 KES: Applied a quickie patch to this in my kes09Jan02 submission