diff options
author | Colin Watson <cjwatson@debian.org> | 2003-09-23 18:08:35 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2003-09-23 18:08:35 +0000 |
commit | d59fd3e421aa81b8e5e118f3f806081df2aca879 (patch) | |
tree | 356a4e607edc979c625bb33db63c656d771478bd /openbsd-compat/bsd-misc.c | |
parent | 7505658c58e96b8d270f1928a0e1fa7f3e0c266b (diff) | |
parent | 45431c9b4677608680cd071768cbf156b316a7e8 (diff) |
Merge 3.7.1p2 to the trunk. I have absolutely no idea yet whether this will
work.
Diffstat (limited to 'openbsd-compat/bsd-misc.c')
-rw-r--r-- | openbsd-compat/bsd-misc.c | 94 |
1 files changed, 77 insertions, 17 deletions
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index b8e9996d5..08b089bdc 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 1999-2000 Damien Miller. All rights reserved. | 2 | * Copyright (c) 1999-2003 Damien Miller. All rights reserved. |
3 | * | 3 | * |
4 | * Redistribution and use in source and binary forms, with or without | 4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions | 5 | * modification, are permitted provided that the following conditions |
@@ -25,13 +25,13 @@ | |||
25 | #include "includes.h" | 25 | #include "includes.h" |
26 | #include "xmalloc.h" | 26 | #include "xmalloc.h" |
27 | 27 | ||
28 | RCSID("$Id: bsd-misc.c,v 1.12 2003/03/18 18:21:41 tim Exp $"); | 28 | RCSID("$Id: bsd-misc.c,v 1.19 2003/08/25 01:16:21 mouring Exp $"); |
29 | 29 | ||
30 | /* | 30 | /* |
31 | * NB. duplicate __progname in case it is an alias for argv[0] | 31 | * NB. duplicate __progname in case it is an alias for argv[0] |
32 | * Otherwise it may get clobbered by setproctitle() | 32 | * Otherwise it may get clobbered by setproctitle() |
33 | */ | 33 | */ |
34 | char *get_progname(char *argv0) | 34 | char *ssh_get_progname(char *argv0) |
35 | { | 35 | { |
36 | #ifdef HAVE___PROGNAME | 36 | #ifdef HAVE___PROGNAME |
37 | extern char *__progname; | 37 | extern char *__progname; |
@@ -41,21 +41,21 @@ char *get_progname(char *argv0) | |||
41 | char *p; | 41 | char *p; |
42 | 42 | ||
43 | if (argv0 == NULL) | 43 | if (argv0 == NULL) |
44 | return "unknown"; /* XXX */ | 44 | return ("unknown"); /* XXX */ |
45 | p = strrchr(argv0, '/'); | 45 | p = strrchr(argv0, '/'); |
46 | if (p == NULL) | 46 | if (p == NULL) |
47 | p = argv0; | 47 | p = argv0; |
48 | else | 48 | else |
49 | p++; | 49 | p++; |
50 | 50 | ||
51 | return xstrdup(p); | 51 | return (xstrdup(p)); |
52 | #endif | 52 | #endif |
53 | } | 53 | } |
54 | 54 | ||
55 | #ifndef HAVE_SETLOGIN | 55 | #ifndef HAVE_SETLOGIN |
56 | int setlogin(const char *name) | 56 | int setlogin(const char *name) |
57 | { | 57 | { |
58 | return(0); | 58 | return (0); |
59 | } | 59 | } |
60 | #endif /* !HAVE_SETLOGIN */ | 60 | #endif /* !HAVE_SETLOGIN */ |
61 | 61 | ||
@@ -63,21 +63,21 @@ int setlogin(const char *name) | |||
63 | int innetgr(const char *netgroup, const char *host, | 63 | int innetgr(const char *netgroup, const char *host, |
64 | const char *user, const char *domain) | 64 | const char *user, const char *domain) |
65 | { | 65 | { |
66 | return(0); | 66 | return (0); |
67 | } | 67 | } |
68 | #endif /* HAVE_INNETGR */ | 68 | #endif /* HAVE_INNETGR */ |
69 | 69 | ||
70 | #if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) | 70 | #if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
71 | int seteuid(uid_t euid) | 71 | int seteuid(uid_t euid) |
72 | { | 72 | { |
73 | return(setreuid(-1,euid)); | 73 | return (setreuid(-1, euid)); |
74 | } | 74 | } |
75 | #endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) */ | 75 | #endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) */ |
76 | 76 | ||
77 | #if !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) | 77 | #if !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) |
78 | int setegid(uid_t egid) | 78 | int setegid(uid_t egid) |
79 | { | 79 | { |
80 | return(setresgid(-1,egid,-1)); | 80 | return(setresgid(-1, egid, -1)); |
81 | } | 81 | } |
82 | #endif /* !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) */ | 82 | #endif /* !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) */ |
83 | 83 | ||
@@ -88,9 +88,9 @@ const char *strerror(int e) | |||
88 | extern char *sys_errlist[]; | 88 | extern char *sys_errlist[]; |
89 | 89 | ||
90 | if ((e >= 0) && (e < sys_nerr)) | 90 | if ((e >= 0) && (e < sys_nerr)) |
91 | return(sys_errlist[e]); | 91 | return (sys_errlist[e]); |
92 | else | 92 | |
93 | return("unlisted error"); | 93 | return ("unlisted error"); |
94 | } | 94 | } |
95 | #endif | 95 | #endif |
96 | 96 | ||
@@ -102,24 +102,25 @@ int utimes(char *filename, struct timeval *tvp) | |||
102 | ub.actime = tvp[0].tv_sec; | 102 | ub.actime = tvp[0].tv_sec; |
103 | ub.modtime = tvp[1].tv_sec; | 103 | ub.modtime = tvp[1].tv_sec; |
104 | 104 | ||
105 | return(utime(filename, &ub)); | 105 | return (utime(filename, &ub)); |
106 | } | 106 | } |
107 | #endif | 107 | #endif |
108 | 108 | ||
109 | #ifndef HAVE_TRUNCATE | 109 | #ifndef HAVE_TRUNCATE |
110 | int truncate (const char *path, off_t length) | 110 | int truncate(const char *path, off_t length) |
111 | { | 111 | { |
112 | int fd, ret, saverrno; | 112 | int fd, ret, saverrno; |
113 | 113 | ||
114 | fd = open(path, O_WRONLY); | 114 | fd = open(path, O_WRONLY); |
115 | if (fd < 0) | 115 | if (fd < 0) |
116 | return -1; | 116 | return (-1); |
117 | 117 | ||
118 | ret = ftruncate(fd, length); | 118 | ret = ftruncate(fd, length); |
119 | saverrno = errno; | 119 | saverrno = errno; |
120 | (void) close (fd); | 120 | close(fd); |
121 | if (ret == -1) | 121 | if (ret == -1) |
122 | errno = saverrno; | 122 | errno = saverrno; |
123 | |||
123 | return(ret); | 124 | return(ret); |
124 | } | 125 | } |
125 | #endif /* HAVE_TRUNCATE */ | 126 | #endif /* HAVE_TRUNCATE */ |
@@ -131,7 +132,7 @@ int truncate (const char *path, off_t length) | |||
131 | int | 132 | int |
132 | setgroups(size_t size, const gid_t *list) | 133 | setgroups(size_t size, const gid_t *list) |
133 | { | 134 | { |
134 | return 0; | 135 | return (0); |
135 | } | 136 | } |
136 | #endif | 137 | #endif |
137 | 138 | ||
@@ -166,3 +167,62 @@ int nanosleep(const struct timespec *req, struct timespec *rem) | |||
166 | 167 | ||
167 | #endif | 168 | #endif |
168 | 169 | ||
170 | #ifndef HAVE_TCGETPGRP | ||
171 | pid_t | ||
172 | tcgetpgrp(int fd) | ||
173 | { | ||
174 | int ctty_pgrp; | ||
175 | |||
176 | if (ioctl(fd, TIOCGPGRP, &ctty_pgrp) == -1) | ||
177 | return(-1); | ||
178 | else | ||
179 | return(ctty_pgrp); | ||
180 | } | ||
181 | #endif /* HAVE_TCGETPGRP */ | ||
182 | |||
183 | #ifndef HAVE_TCSENDBREAK | ||
184 | int | ||
185 | tcsendbreak(int fd, int duration) | ||
186 | { | ||
187 | # if defined(TIOCSBRK) && defined(TIOCCBRK) | ||
188 | struct timeval sleepytime; | ||
189 | |||
190 | sleepytime.tv_sec = 0; | ||
191 | sleepytime.tv_usec = 400000; | ||
192 | if (ioctl(fd, TIOCSBRK, 0) == -1) | ||
193 | return (-1); | ||
194 | (void)select(0, 0, 0, 0, &sleepytime); | ||
195 | if (ioctl(fd, TIOCCBRK, 0) == -1) | ||
196 | return (-1); | ||
197 | return (0); | ||
198 | # else | ||
199 | return -1; | ||
200 | # endif | ||
201 | } | ||
202 | #endif /* HAVE_TCSENDBREAK */ | ||
203 | |||
204 | mysig_t | ||
205 | mysignal(int sig, mysig_t act) | ||
206 | { | ||
207 | #ifdef HAVE_SIGACTION | ||
208 | struct sigaction sa, osa; | ||
209 | |||
210 | if (sigaction(sig, NULL, &osa) == -1) | ||
211 | return (mysig_t) -1; | ||
212 | if (osa.sa_handler != act) { | ||
213 | memset(&sa, 0, sizeof(sa)); | ||
214 | sigemptyset(&sa.sa_mask); | ||
215 | sa.sa_flags = 0; | ||
216 | #ifdef SA_INTERRUPT | ||
217 | if (sig == SIGALRM) | ||
218 | sa.sa_flags |= SA_INTERRUPT; | ||
219 | #endif | ||
220 | sa.sa_handler = act; | ||
221 | if (sigaction(sig, &sa, NULL) == -1) | ||
222 | return (mysig_t) -1; | ||
223 | } | ||
224 | return (osa.sa_handler); | ||
225 | #else | ||
226 | return (signal(sig, act)); | ||
227 | #endif | ||
228 | } | ||