diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-09-26 17:03:23 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-09-26 17:03:23 +0000 |
commit | 237f35a919f78508b7fbbc53a554500a22728fff (patch) | |
tree | 60f026e03ed3cebe7b2b13df20ff9ffc3129b26d | |
parent | afe6975dc6cc1749810caf2951ed3c151119a4d0 (diff) |
avoid strdup. and, while at it, fix a file leak at sigexit time spotted
by ish
-rw-r--r-- | usr.sbin/apmd/apmd.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/usr.sbin/apmd/apmd.c b/usr.sbin/apmd/apmd.c index 39524c6c21b..f8d11482c2c 100644 --- a/usr.sbin/apmd/apmd.c +++ b/usr.sbin/apmd/apmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apmd.c,v 1.28 2003/06/11 23:33:25 deraadt Exp $ */ +/* $OpenBSD: apmd.c,v 1.29 2003/09/26 17:03:22 deraadt Exp $ */ /* * Copyright (c) 1995, 1996 John T. Kohl @@ -29,7 +29,7 @@ * */ -#include <sys/types.h> +#include <sys/param.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <sys/socket.h> @@ -50,7 +50,6 @@ #include "pathnames.h" #include "apm-proto.h" -#define MAX(a,b) (a > b ? a : b) #define TRUE 1 #define FALSE 0 @@ -70,10 +69,12 @@ void stand_by(int ctl_fd); void sigexit(int signo); void make_noise(int howmany); void do_etc_file(const char *file); +void sockunlink(void); void sigexit(int signo) { + sockunlink(); _exit(1); } @@ -166,12 +167,12 @@ power_status(int fd, int force, struct apm_power_info *pinfo) return acon; } -char *socketname; +char socketname[MAXPATHLEN]; void sockunlink(void) { - if (socketname) + if (socketname[0]) remove(socketname); } @@ -199,7 +200,7 @@ bind_socket(const char *sockname) error("cannot set socket mode/owner/group to 660/0/0", NULL); listen(sock, 1); - socketname = strdup(sockname); + strlcpy(socketname, sockname, sizeof socketname); atexit(sockunlink); return sock; |