summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/misc.c b/misc.c
index c457a952c..84c94f9b6 100644
--- a/misc.c
+++ b/misc.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25#include "includes.h" 25#include "includes.h"
26RCSID("$OpenBSD: misc.c,v 1.21 2003/04/12 10:15:36 markus Exp $"); 26RCSID("$OpenBSD: misc.c,v 1.20 2002/12/13 10:03:15 markus Exp $");
27 27
28#include "misc.h" 28#include "misc.h"
29#include "log.h" 29#include "log.h"
@@ -60,7 +60,7 @@ set_nonblock(int fd)
60 debug2("fd %d is O_NONBLOCK", fd); 60 debug2("fd %d is O_NONBLOCK", fd);
61 return; 61 return;
62 } 62 }
63 debug2("fd %d setting O_NONBLOCK", fd); 63 debug("fd %d setting O_NONBLOCK", fd);
64 val |= O_NONBLOCK; 64 val |= O_NONBLOCK;
65 if (fcntl(fd, F_SETFL, val) == -1) 65 if (fcntl(fd, F_SETFL, val) == -1)
66 debug("fcntl(%d, F_SETFL, O_NONBLOCK): %s", 66 debug("fcntl(%d, F_SETFL, O_NONBLOCK): %s",
@@ -308,18 +308,47 @@ addargs(arglist *args, char *fmt, ...)
308{ 308{
309 va_list ap; 309 va_list ap;
310 char buf[1024]; 310 char buf[1024];
311 int nalloc;
311 312
312 va_start(ap, fmt); 313 va_start(ap, fmt);
313 vsnprintf(buf, sizeof(buf), fmt, ap); 314 vsnprintf(buf, sizeof(buf), fmt, ap);
314 va_end(ap); 315 va_end(ap);
315 316
317 nalloc = args->nalloc;
316 if (args->list == NULL) { 318 if (args->list == NULL) {
317 args->nalloc = 32; 319 nalloc = 32;
318 args->num = 0; 320 args->num = 0;
319 } else if (args->num+2 >= args->nalloc) 321 } else if (args->num+2 >= nalloc)
320 args->nalloc *= 2; 322 nalloc *= 2;
321 323
322 args->list = xrealloc(args->list, args->nalloc * sizeof(char *)); 324 args->list = xrealloc(args->list, nalloc * sizeof(char *));
325 args->nalloc = nalloc;
323 args->list[args->num++] = xstrdup(buf); 326 args->list[args->num++] = xstrdup(buf);
324 args->list[args->num] = NULL; 327 args->list[args->num] = NULL;
325} 328}
329
330mysig_t
331mysignal(int sig, mysig_t act)
332{
333#ifdef HAVE_SIGACTION
334 struct sigaction sa, osa;
335
336 if (sigaction(sig, NULL, &osa) == -1)
337 return (mysig_t) -1;
338 if (osa.sa_handler != act) {
339 memset(&sa, 0, sizeof(sa));
340 sigemptyset(&sa.sa_mask);
341 sa.sa_flags = 0;
342#if defined(SA_INTERRUPT)
343 if (sig == SIGALRM)
344 sa.sa_flags |= SA_INTERRUPT;
345#endif
346 sa.sa_handler = act;
347 if (sigaction(sig, &sa, NULL) == -1)
348 return (mysig_t) -1;
349 }
350 return (osa.sa_handler);
351#else
352 return (signal(sig, act));
353#endif
354}