Thu, 07 Apr 2005 14:55:02 +0000
[gaim-migrate @ 12431]
" The following log snippets should explain it: " --rlaager
(20:24:00) rlaager: Regarding the signal handling
conversation the other day... I've written a patch to stop
calling signal handlers and return as soon as we find one
signal handler that returns TRUE to indicate that it's
handled the signal. Is this the right approach?
(20:24:22) Ethan Blanton (Paco-Paco): the trouble is that it's
documented to behave exactly the way it does
(20:24:31) Ethan Blanton (Paco-Paco): so changing it is
notbackwards compatible
(20:24:31) rlaager: I'm talking for HEAD.
(20:24:41) Ethan Blanton (Paco-Paco): oh, I think that's a
good approach, yes
(20:24:53) rlaager: The way I've described is how I
*expected* it to work, having not read the documentation.
(20:25:09) Ethan Blanton (Paco-Paco): I'm convinced
(20:27:04) Stu Tomlinson (nosnilmot): rlaager: this, I
assume, breaks the generic-ness of signals, by assuming
that any that return values return booleans?
(20:27:26) Ethan Blanton (Paco-Paco): please break it
(20:27:33) Ethan Blanton (Paco-Paco): we already have
out-parameters
(20:27:42) rlaager: nosnilmot: from what I can see, the
return type is handled as a (void *)... so I'm checking that
ret_value != NULL
(20:27:57) rlaager: nosnilmot: that's the correct way to do it,
right?
...
(20:29:01) Ethan Blanton (Paco-Paco): allowing a
meaningful return value is an over-engineering
(20:30:07) rlaager: even after this patch, you should be able
to return meaningful return values
(20:30:15) rlaager: it'll just short-circuit on the first handler
that does
committer: Luke Schierer <lschiere@pidgin.im>
| 2086 | 1 | /* This file is part of the Project Athena Zephyr Notification System. |
| 2 | * It contains source for the ZGetVariable, ZSetVariable, and ZUnsetVariable | |
| 3 | * functions. | |
| 4 | * | |
| 5 | * Created by: Robert French | |
| 6 | * | |
| 7 | * $Source$ | |
|
10772
783fa6f14695
[gaim-migrate @ 12380]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10592
diff
changeset
|
8 | * $Author: nosnilmot $ |
| 2086 | 9 | * |
| 10 | * Copyright (c) 1987 by the Massachusetts Institute of Technology. | |
| 11 | * For copying and distribution information, see the file | |
| 12 | * "mit-copyright.h". | |
| 13 | */ | |
| 14 | /* $Header$ */ | |
| 15 | ||
| 16 | #ifndef lint | |
| 17 | static char rcsid_ZVariables_c[] = "$Header$"; | |
| 18 | #endif | |
| 19 | ||
|
8792
b0645c9dc276
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
20 | #include "internal.h" |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
4272
diff
changeset
|
21 | #include "util.h" |
| 2086 | 22 | |
| 23 | #include <ctype.h> | |
| 24 | #include <pwd.h> | |
| 25 | ||
| 26 | static int get_localvarfile __P((char *bfr)); | |
| 27 | static char *get_varval __P((char *fn, char *val)); | |
| 28 | static int varline __P((char *bfr, char *var)); | |
| 29 | ||
| 30 | char *ZGetVariable(var) | |
| 31 | char *var; | |
| 32 | { | |
| 33 | char varfile[128], *ret; | |
| 34 | ||
| 35 | if (get_localvarfile(varfile)) | |
| 36 | return ((char *)0); | |
| 37 | ||
| 38 | if ((ret = get_varval(varfile, var)) != ZERR_NONE) | |
| 39 | return (ret); | |
| 40 | ||
| 41 | sprintf(varfile, "%s/zephyr.vars", CONFDIR); | |
| 42 | return (get_varval(varfile, var)); | |
| 43 | } | |
| 44 | ||
| 45 | Code_t ZSetVariable(var, value) | |
| 46 | char *var; | |
| 47 | char *value; | |
| 48 | { | |
| 49 | int written; | |
| 50 | FILE *fpin, *fpout; | |
| 51 | char varfile[128], varfilebackup[128], varbfr[512]; | |
| 52 | ||
| 53 | written = 0; | |
| 54 | ||
| 55 | if (get_localvarfile(varfile)) | |
| 56 | return (ZERR_INTERNAL); | |
| 57 | ||
| 58 | (void) strcpy(varfilebackup, varfile); | |
| 59 | (void) strcat(varfilebackup, ".backup"); | |
| 60 | ||
|
10592
cd4c3a7d7bdf
[gaim-migrate @ 11998]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
61 | if (!(fpout = fopen(varfilebackup, "w"))) |
| 2086 | 62 | return (errno); |
|
10592
cd4c3a7d7bdf
[gaim-migrate @ 11998]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
63 | if ((fpin = fopen(varfile, "r")) != NULL) { |
| 2086 | 64 | while (fgets(varbfr, sizeof varbfr, fpin) != (char *) 0) { |
| 65 | if (varbfr[strlen(varbfr)-1] < ' ') | |
| 66 | varbfr[strlen(varbfr)-1] = '\0'; | |
| 67 | if (varline(varbfr, var)) { | |
| 68 | fprintf(fpout, "%s = %s\n", var, value); | |
| 69 | written = 1; | |
| 70 | } | |
| 71 | else | |
| 72 | fprintf(fpout, "%s\n", varbfr); | |
| 73 | } | |
| 74 | (void) fclose(fpin); /* don't care about errs on input */ | |
| 75 | } | |
| 76 | if (!written) | |
| 77 | fprintf(fpout, "%s = %s\n", var, value); | |
| 78 | if (fclose(fpout) == EOF) | |
| 79 | return(EIO); /* can't rely on errno */ | |
|
10592
cd4c3a7d7bdf
[gaim-migrate @ 11998]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
80 | if (rename(varfilebackup, varfile)) |
| 2086 | 81 | return (errno); |
| 82 | return (ZERR_NONE); | |
| 83 | } | |
| 84 | ||
| 85 | Code_t ZUnsetVariable(var) | |
| 86 | char *var; | |
| 87 | { | |
| 88 | FILE *fpin, *fpout; | |
| 89 | char varfile[128], varfilebackup[128], varbfr[512]; | |
| 90 | ||
| 91 | if (get_localvarfile(varfile)) | |
| 92 | return (ZERR_INTERNAL); | |
| 93 | ||
| 94 | (void) strcpy(varfilebackup, varfile); | |
| 95 | (void) strcat(varfilebackup, ".backup"); | |
| 96 | ||
|
10592
cd4c3a7d7bdf
[gaim-migrate @ 11998]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
97 | if (!(fpout = fopen(varfilebackup, "w"))) |
| 2086 | 98 | return (errno); |
|
10592
cd4c3a7d7bdf
[gaim-migrate @ 11998]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
99 | if ((fpin = fopen(varfile, "r")) != NULL) { |
| 2086 | 100 | while (fgets(varbfr, sizeof varbfr, fpin) != (char *) 0) { |
| 101 | if (varbfr[strlen(varbfr)-1] < ' ') | |
| 102 | varbfr[strlen(varbfr)-1] = '\0'; | |
| 103 | if (!varline(varbfr, var)) | |
| 104 | fprintf(fpout, "%s\n", varbfr); | |
| 105 | } | |
| 106 | (void) fclose(fpin); /* don't care about read close errs */ | |
| 107 | } | |
| 108 | if (fclose(fpout) == EOF) | |
| 109 | return(EIO); /* errno isn't reliable */ | |
|
10592
cd4c3a7d7bdf
[gaim-migrate @ 11998]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
110 | if (rename(varfilebackup, varfile)) |
| 2086 | 111 | return (errno); |
| 112 | return (ZERR_NONE); | |
| 113 | } | |
| 114 | ||
| 115 | static int get_localvarfile(bfr) | |
| 116 | char *bfr; | |
| 117 | { | |
|
4272
fd89c8c4964d
[gaim-migrate @ 4523]
Robert McQueen <robot101@debian.org>
parents:
4271
diff
changeset
|
118 | const char *envptr; |
| 2086 | 119 | struct passwd *pwd; |
| 120 | ||
|
4272
fd89c8c4964d
[gaim-migrate @ 4523]
Robert McQueen <robot101@debian.org>
parents:
4271
diff
changeset
|
121 | envptr = gaim_home_dir(); |
| 2086 | 122 | if (envptr) |
| 123 | (void) strcpy(bfr, envptr); | |
| 124 | else { | |
| 125 | if (!(pwd = getpwuid((int) getuid()))) { | |
| 126 | fprintf(stderr, "Zephyr internal failure: Can't find your entry in /etc/passwd\n"); | |
| 127 | return (1); | |
| 128 | } | |
| 129 | (void) strcpy(bfr, pwd->pw_dir); | |
| 130 | } | |
| 131 | ||
| 132 | (void) strcat(bfr, "/"); | |
| 133 | (void) strcat(bfr, ".zephyr.vars"); | |
| 134 | return (0); | |
| 135 | } | |
| 136 | ||
| 137 | static char *get_varval(fn, var) | |
| 138 | char *fn; | |
| 139 | char *var; | |
| 140 | { | |
| 141 | FILE *fp; | |
| 142 | static char varbfr[512]; | |
| 143 | int i; | |
| 144 | ||
|
10592
cd4c3a7d7bdf
[gaim-migrate @ 11998]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
145 | fp = fopen(fn, "r"); |
| 2086 | 146 | if (!fp) |
| 147 | return ((char *)0); | |
| 148 | ||
| 149 | while (fgets(varbfr, sizeof varbfr, fp) != (char *) 0) { | |
| 150 | if (varbfr[strlen(varbfr)-1] < ' ') | |
| 151 | varbfr[strlen(varbfr)-1] = '\0'; | |
| 152 | if (!(i = varline(varbfr, var))) | |
| 153 | continue; | |
| 154 | (void) fclose(fp); /* open read-only, don't care */ | |
| 155 | return (varbfr+i); | |
| 156 | } | |
| 157 | (void) fclose(fp); /* open read-only, don't care */ | |
| 158 | return ((char *)0); | |
| 159 | } | |
| 160 | ||
| 161 | /* If the variable in the line bfr[] is the same as var, return index to | |
| 162 | the variable value, else return 0. */ | |
| 163 | static int varline(bfr, var) | |
| 164 | char *bfr; | |
| 165 | char *var; | |
| 166 | { | |
| 167 | register char *cp; | |
| 168 | ||
| 169 | ||
| 170 | if (!bfr[0] || bfr[0] == '#') /* comment or null line */ | |
| 171 | return (0); | |
| 172 | ||
| 173 | cp = bfr; | |
| 174 | while (*cp && !isspace(*cp) && (*cp != '=')) | |
| 175 | cp++; | |
| 176 | ||
| 177 | #define max(a,b) ((a > b) ? (a) : (b)) | |
| 178 | ||
| 179 | if (strncasecmp(bfr, var, max(strlen(var),cp - bfr))) | |
| 180 | return(0); /* var is not the var in | |
| 181 | bfr ==> no match */ | |
| 182 | ||
| 183 | cp = strchr(bfr, '='); | |
| 184 | if (!cp) | |
| 185 | return(0); | |
| 186 | cp++; | |
| 187 | while (*cp && isspace(*cp)) /* space up to variable value */ | |
| 188 | cp++; | |
| 189 | ||
| 190 | return (cp - bfr); /* return index */ | |
| 191 | } |