chiark
/
gitweb
/
~ian
/
userv.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
@@ -24,6 +24,7 @@
[userv.git]
/
client.c
diff --git
a/client.c
b/client.c
index 740aac54e44ecd357b2e21a61b58f82ab22b71b4..c6b259bbd899c73046766ab8a1e33a572efe5ba5 100644
(file)
--- a/
client.c
+++ b/
client.c
@@
-168,7
+168,7
@@
static void NONRETURNPRINTFFORMAT(1,2) miscerror(const char *fmt, ...) {
exit(-1);
}
exit(-1);
}
-static void NONRETURNPRINTFFORMAT(1,2) syscallerror(const char *fmt, ...) {
+static void NONRETURNPRINTFFORMAT(1,2)
f
syscallerror(const char *fmt, ...) {
va_list al;
int e;
va_list al;
int e;
@@
-181,6
+181,10
@@
static void NONRETURNPRINTFFORMAT(1,2) syscallerror(const char *fmt, ...) {
exit(-1);
}
exit(-1);
}
+void syscallerror(const char *what) {
+ fsyscallerror("%s",what);
+}
+
static void NONRETURNING protoreaderror(FILE *file, const char *where) {
int e;
static void NONRETURNING protoreaderror(FILE *file, const char *where) {
int e;
@@
-280,7
+284,7
@@
static void getprogress(struct progress_msg *progress_r, FILE *file) {
for (i=0; i<progress_r->data.errmsg.messagelen; i++) {
c= working_getc(file);
if (c==EOF) protoreaderror(file,"in error message");
for (i=0; i<progress_r->data.errmsg.messagelen; i++) {
c= working_getc(file);
if (c==EOF) protoreaderror(file,"in error message");
- if (
isprint(
c)) putc(c,stderr);
+ if (
ISCHAR(isprint,
c)) putc(c,stderr);
else fprintf(stderr,"\\x%02x",(unsigned char)c);
}
putc('\n',stderr);
else fprintf(stderr,"\\x%02x",(unsigned char)c);
}
putc('\n',stderr);
@@
-300,18
+304,7
@@
static void getprogress(struct progress_msg *progress_r, FILE *file) {
* the signal asynchronicity starts. They can do anything they like.
*/
* the signal asynchronicity starts. They can do anything they like.
*/
-static void *xmalloc(size_t s) {
- void *p;
- p= malloc(s?s:1);
- if (!p) syscallerror("malloc (%lu bytes)",(unsigned long)s);
- return p;
-}
-
-static void *xrealloc(void *p, size_t s) {
- p= realloc(p,s);
- if (!p) syscallerror("realloc (%lu bytes)",(unsigned long)s);
- return p;
-}
+/* This includes xmalloc and xrealloc from both.c */
static void xfwritestring(const char *s, FILE *file) {
int l;
static void xfwritestring(const char *s, FILE *file) {
int l;
@@
-348,7
+341,7
@@
static void disconnect(void) /* DOES return, unlike in daemon */ {
event_mbuf.type= et_disconnect;
r= fwrite(&event_mbuf,1,sizeof(event_mbuf),swfile);
if ((r != sizeof(event_mbuf) || fflush(swfile)) && errno != EPIPE)
event_mbuf.type= et_disconnect;
r= fwrite(&event_mbuf,1,sizeof(event_mbuf),swfile);
if ((r != sizeof(event_mbuf) || fflush(swfile)) && errno != EPIPE)
- syscallerror("write to server when disconnecting
\n
");
+ syscallerror("write to server when disconnecting");
}
systemerror= 1;
}
}
systemerror= 1;
}
@@
-422,7
+415,7
@@
struct optioninfo {
optionfunction *fn;
};
optionfunction *fn;
};
-static void usage(
void
) {
+static void usage(
FILE *stream
) {
if (fputs(
"usage: userv <options> [--] <service-user> <service-name> [<argument> ...]\n"
"usage: userv <options> -B|--builtin [--] <builtin-service> [<info-argument> ...]\n"
if (fputs(
"usage: userv <options> [--] <service-user> <service-name> [<argument> ...]\n"
"usage: userv <options> -B|--builtin [--] <builtin-service> [<info-argument> ...]\n"
@@
-431,7
+424,7
@@
static void usage(void) {
" -t|--timeout <seconds>\n"
" -S|--signals <status>|number|number-nocore|highbit|stdout\n"
" -w|--fdwait <fd>=wait|nowait|close\n"
" -t|--timeout <seconds>\n"
" -S|--signals <status>|number|number-nocore|highbit|stdout\n"
" -w|--fdwait <fd>=wait|nowait|close\n"
- " -P|--sigpipe -H|--hidecwd -h|--help --copyright\n"
+ " -P|--sigpipe -H|--hidecwd -h|--help
|--version
--copyright\n"
" --override <configuration-data> } available only\n"
" --override-file <filename> } to root\n"
" --spoof-user <username> } or same user\n"
" --override <configuration-data> } available only\n"
" --override-file <filename> } to root\n"
" --spoof-user <username> } or same user\n"
@@
-441,8
+434,8
@@
static void usage(void) {
" for help, type `userv -B help'; remember to quote multi-word X\n"
"userv and uservd version " VERSION VEREXT "; copyright (C)1996-1999 Ian Jackson.\n"
"there is NO WARRANTY; type `userv --copyright' for details.\n",
" for help, type `userv -B help'; remember to quote multi-word X\n"
"userv and uservd version " VERSION VEREXT "; copyright (C)1996-1999 Ian Jackson.\n"
"there is NO WARRANTY; type `userv --copyright' for details.\n",
- st
derr
) < 0)
- syscallerror("write usage
to stderr
");
+ st
ream
) < 0)
+ syscallerror("write usage
message
");
}
static void NONRETURNPRINTFFORMAT(1,2) usageerror(const char *fmt, ...) {
}
static void NONRETURNPRINTFFORMAT(1,2) usageerror(const char *fmt, ...) {
@@
-451,7
+444,7
@@
static void NONRETURNPRINTFFORMAT(1,2) usageerror(const char *fmt, ...) {
fputs("userv: ",stderr);
vfprintf(stderr,fmt,al);
fputs("\n\n",stderr);
fputs("userv: ",stderr);
vfprintf(stderr,fmt,al);
fputs("\n\n",stderr);
- usage();
+ usage(
stderr
);
exit(-1);
}
exit(-1);
}
@@
-590,9
+583,9
@@
static void of_file(const struct optioninfo *oip, const char *value, char *key)
}
r= fstat(copyfd,&stab);
if (r) {
}
r= fstat(copyfd,&stab);
if (r) {
- if (oip) syscallerror("check filedescriptor %lu (named as target of file "
- "descriptor redirection for %lu)",copyfd,fd);
- else syscallerror("check basic filedescriptor %lu at program start",copyfd);
+ if (oip)
f
syscallerror("check filedescriptor %lu (named as target of file "
+
"descriptor redirection for %lu)",copyfd,fd);
+ else
f
syscallerror("check basic filedescriptor %lu at program start",copyfd);
}
fdsetup[fd].copyfd= copyfd;
}
}
fdsetup[fd].copyfd= copyfd;
}
@@
-678,7
+671,14
@@
static void of_hidecwd(const struct optioninfo *oip, const char *value, char *ke
}
static void of_help(const struct optioninfo *oip, const char *value, char *key) {
}
static void of_help(const struct optioninfo *oip, const char *value, char *key) {
- usage();
+ usage(stdout);
+ if (fclose(stdout)) syscallerror("fclose stdout after writing usage message");
+ exit(0);
+}
+
+static void of_version(const struct optioninfo *oip, const char *value, char *key) {
+ if (puts(VERSION VEREXT) == EOF || fclose(stdout))
+ syscallerror("write version number");
exit(0);
}
exit(0);
}
@@
-694,7
+694,7
@@
static void of_copyright(const struct optioninfo *oip, const char *value, char *
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General\n"
" Public License for more details.\n\n"
" You should have received a copy of the GNU General Public License along\n"
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General\n"
" Public License for more details.\n\n"
" You should have received a copy of the GNU General Public License along\n"
-" with userv; if not, write to Ian Jackson <ian@
chiark
.greenend.org.uk> or\n"
+" with userv; if not, write to Ian Jackson <ian@
davenant
.greenend.org.uk> or\n"
" to the Free Software Foundation, 59 Temple Place - Suite 330, Boston,\n"
" MA 02111-1307, USA.\n",
stdout) < 0) syscallerror("write usage to stderr");
" to the Free Software Foundation, 59 Temple Place - Suite 330, Boston,\n"
" MA 02111-1307, USA.\n",
stdout) < 0) syscallerror("write usage to stderr");
@@
-731,6
+731,7
@@
const struct optioninfo optioninfos[]= {
{ 'H', "hidecwd", 0, of_hidecwd },
{ 'B', "builtin", 0, of_builtin },
{ 'h', "help", 0, of_help },
{ 'H', "hidecwd", 0, of_hidecwd },
{ 'B', "builtin", 0, of_builtin },
{ 'h', "help", 0, of_help },
+ { 0, "version", 0, of_version },
{ 0, "copyright", 0, of_copyright },
{ 0, "override", 1, of_override },
{ 0, "override-file", 1, of_overridefile },
{ 0, "copyright", 0, of_copyright },
{ 0, "override", 1, of_override },
{ 0, "override-file", 1, of_overridefile },
@@
-865,7
+866,7
@@
static void determine_users(void) {
}
if (!loginname) {
pw= getpwuid(myuid); if (!pw) miscerror("cannot determine your login name");
}
if (!loginname) {
pw= getpwuid(myuid); if (!pw) miscerror("cannot determine your login name");
- loginname=
pw->pw_name
;
+ loginname=
xstrsave(pw->pw_name)
;
}
if (!strcmp(serviceuser,"-")) serviceuser= loginname;
}
if (!strcmp(serviceuser,"-")) serviceuser= loginname;
@@
-946,7
+947,7
@@
static void process_override(const char *servicename) {
break;
case ot_file:
ovfile= fopen(overridevalue,"r");
break;
case ot_file:
ovfile= fopen(overridevalue,"r");
- if (!ovfile) syscallerror("open overriding configuration file `%s'",overridevalue);
+ if (!ovfile)
f
syscallerror("open overriding configuration file `%s'",overridevalue);
ovbuf= 0; ovavail= ovused= 0;
while ((c= getc(ovfile)) != EOF) {
if (!c) miscerror("overriding config file `%s' contains null(s)",overridevalue);
ovbuf= 0; ovavail= ovused= 0;
while ((c= getc(ovfile)) != EOF) {
if (!c) miscerror("overriding config file `%s' contains null(s)",overridevalue);
@@
-958,7
+959,7
@@
static void process_override(const char *servicename) {
ovbuf[ovused++]= c;
}
if (ferror(ovfile) || fclose(ovfile))
ovbuf[ovused++]= c;
}
if (ferror(ovfile) || fclose(ovfile))
- syscallerror("read overriding configuration file `%s'",overridevalue);
+
f
syscallerror("read overriding configuration file `%s'",overridevalue);
ovbuf= xrealloc(ovbuf,ovused+1);
ovbuf[ovused]= 0;
break;
ovbuf= xrealloc(ovbuf,ovused+1);
ovbuf[ovused]= 0;
break;
@@
-995,7
+996,7
@@
static int server_connect(void) {
if (errno == ECONNREFUSED || errno == ENOENT)
syscallerror("uservd daemon is not running - service not available");
if (errno != EINTR)
if (errno == ECONNREFUSED || errno == ENOENT)
syscallerror("uservd daemon is not running - service not available");
if (errno != EINTR)
- syscallerror("unable to connect to uservd daemon: %m");
+
f
syscallerror("unable to connect to uservd daemon: %m");
}
return sfd;
}
return sfd;
@@
-1028,16
+1029,16
@@
static void server_preparepipes(void) {
assert(!pipepathbuf[PIPEPATHMAXLEN]);
priv_resume();
if (unlink(pipepathbuf) && errno != ENOENT)
assert(!pipepathbuf[PIPEPATHMAXLEN]);
priv_resume();
if (unlink(pipepathbuf) && errno != ENOENT)
- syscallerror("remove any old pipe `%s'",pipepathbuf);
+
f
syscallerror("remove any old pipe `%s'",pipepathbuf);
if (mkfifo(pipepathbuf,0600)) /* permissions are irrelevant */
if (mkfifo(pipepathbuf,0600)) /* permissions are irrelevant */
- syscallerror("create pipe `%s'",pipepathbuf);
+
f
syscallerror("create pipe `%s'",pipepathbuf);
tempfd= open(pipepathbuf,O_RDWR);
tempfd= open(pipepathbuf,O_RDWR);
- if (tempfd<0) syscallerror("prelim open pipe `%s' for read+write",pipepathbuf);
+ if (tempfd<0)
f
syscallerror("prelim open pipe `%s' for read+write",pipepathbuf);
assert(fdsetup[fd].mods & (fdm_read|fdm_write));
fdsetup[fd].pipefd=
open(pipepathbuf, (fdsetup[fd].mods & fdm_read) ? O_WRONLY : O_RDONLY);
assert(fdsetup[fd].mods & (fdm_read|fdm_write));
fdsetup[fd].pipefd=
open(pipepathbuf, (fdsetup[fd].mods & fdm_read) ? O_WRONLY : O_RDONLY);
- if (fdsetup[fd].pipefd<0) syscallerror("real open pipe `%s'",pipepathbuf);
- if (close(tempfd)) syscallerror("close prelim fd onto pipe `%s'",pipepathbuf);
+ if (fdsetup[fd].pipefd<0)
f
syscallerror("real open pipe `%s'",pipepathbuf);
+ if (close(tempfd))
f
syscallerror("close prelim fd onto pipe `%s'",pipepathbuf);
priv_suspend();
}
}
priv_suspend();
}
}
@@
-1142,13
+1143,13
@@
static void connect_pipes(void) {
fdsetup[fd].copyfd=
open(fdsetup[fd].filename,fdsetup[fd].oflags|O_NOCTTY,0777);
if (fdsetup[fd].copyfd<0)
fdsetup[fd].copyfd=
open(fdsetup[fd].filename,fdsetup[fd].oflags|O_NOCTTY,0777);
if (fdsetup[fd].copyfd<0)
- syscallerror("open file `%s' for fd %d",fdsetup[fd].filename,fd);
+
f
syscallerror("open file `%s' for fd %d",fdsetup[fd].filename,fd);
}
blocksignals(SIG_BLOCK);
child= fork();
fdsetup[fd].catpid= child;
blocksignals(SIG_UNBLOCK);
}
blocksignals(SIG_BLOCK);
child= fork();
fdsetup[fd].catpid= child;
blocksignals(SIG_UNBLOCK);
- if (child==-1) syscallerror("fork for cat for fd %d",fd);
+ if (child==-1)
f
syscallerror("fork for cat for fd %d",fd);
if (!child) {
snprintf(catnamebuf,sizeof(catnamebuf),"cat fd%d",fd);
catnamebuf[sizeof(catnamebuf)-1]= 0;
if (!child) {
snprintf(catnamebuf,sizeof(catnamebuf),"cat fd%d",fd);
catnamebuf[sizeof(catnamebuf)-1]= 0;
@@
-1168,8
+1169,8
@@
static void connect_pipes(void) {
exit(-1);
}
if (fdsetup[fd].copyfd>2)
exit(-1);
}
if (fdsetup[fd].copyfd>2)
- if (close(fdsetup[fd].copyfd)) syscallerror("close real fd for %d",fd);
- if (close(fdsetup[fd].pipefd)) syscallerror("close pipe fd for %d",fd);
+ if (close(fdsetup[fd].copyfd))
f
syscallerror("close real fd for %d",fd);
+ if (close(fdsetup[fd].pipefd))
f
syscallerror("close pipe fd for %d",fd);
}
}
}
}
@@
-1204,7
+1205,7
@@
static void dispose_remaining_pipes(void) {
blocksignals(SIG_BLOCK);
for (fd=0; fd<fdsetupsize; fd++) {
if (!(fdsetup[fd].catpid!=-1 && (fdsetup[fd].mods & fdm_close))) continue;
blocksignals(SIG_BLOCK);
for (fd=0; fd<fdsetupsize; fd++) {
if (!(fdsetup[fd].catpid!=-1 && (fdsetup[fd].mods & fdm_close))) continue;
- if (kill(fdsetup[fd].catpid,SIGKILL)) syscallerror("kill cat for %d",fd);
+ if (kill(fdsetup[fd].catpid,SIGKILL))
f
syscallerror("kill cat for %d",fd);
fdsetup[fd].killed= 1;
}
blocksignals(SIG_UNBLOCK);
fdsetup[fd].killed= 1;
}
blocksignals(SIG_UNBLOCK);