mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
exit 9p on interrupt signal. should do better job here.
This commit is contained in:
parent
d371199605
commit
3e6107910e
1 changed files with 12 additions and 2 deletions
14
src/cmd/9p.c
14
src/cmd/9p.c
|
@ -1,4 +1,5 @@
|
||||||
#include <u.h>
|
#include <u.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
#include <fcall.h>
|
#include <fcall.h>
|
||||||
#include <fs.h>
|
#include <fs.h>
|
||||||
|
@ -54,6 +55,8 @@ threadmain(int argc, char **argv)
|
||||||
usage();
|
usage();
|
||||||
}ARGEND
|
}ARGEND
|
||||||
|
|
||||||
|
signal(SIGINT, SIG_DFL);
|
||||||
|
|
||||||
if(argc < 1)
|
if(argc < 1)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
|
@ -180,7 +183,7 @@ void
|
||||||
xwrite(int argc, char **argv)
|
xwrite(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
int n;
|
int n, did;
|
||||||
Fid *fid;
|
Fid *fid;
|
||||||
|
|
||||||
ARGBEGIN{
|
ARGBEGIN{
|
||||||
|
@ -191,10 +194,17 @@ xwrite(int argc, char **argv)
|
||||||
if(argc != 1)
|
if(argc != 1)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
|
did = 0;
|
||||||
fid = xopen(argv[0], OWRITE|OTRUNC);
|
fid = xopen(argv[0], OWRITE|OTRUNC);
|
||||||
while((n = read(0, buf, sizeof buf)) > 0)
|
while((n = read(0, buf, sizeof buf)) > 0){
|
||||||
|
did = 1;
|
||||||
if(fswrite(fid, buf, n) != n)
|
if(fswrite(fid, buf, n) != n)
|
||||||
sysfatal("write error: %r");
|
sysfatal("write error: %r");
|
||||||
|
}
|
||||||
|
if(n == 0 && !did){
|
||||||
|
if(fswrite(fid, buf, 0) != 0)
|
||||||
|
sysfatal("write error: %r");
|
||||||
|
}
|
||||||
if(n < 0)
|
if(n < 0)
|
||||||
sysfatal("read error: %r");
|
sysfatal("read error: %r");
|
||||||
exits(0);
|
exits(0);
|
||||||
|
|
Loading…
Reference in a new issue