texit 9p on interrupt signal. should do better job here. - plan9port - [fork] Plan 9 from user space
(HTM) git clone git://src.adamsgaard.dk/plan9port
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 3e6107910ecbf6034ec277a8b181d27a3033a0fa
(DIR) parent d371199605e09d56b95de00e9866cf4fea2d8615
(HTM) Author: rsc <devnull@localhost>
Date: Fri, 22 Oct 2004 17:05:24 +0000
exit 9p on interrupt signal. should do better job here.
Diffstat:
M src/cmd/9p.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
---
(DIR) diff --git a/src/cmd/9p.c b/src/cmd/9p.c
t@@ -1,4 +1,5 @@
#include <u.h>
+#include <signal.h>
#include <libc.h>
#include <fcall.h>
#include <fs.h>
t@@ -54,6 +55,8 @@ threadmain(int argc, char **argv)
usage();
}ARGEND
+ signal(SIGINT, SIG_DFL);
+
if(argc < 1)
usage();
t@@ -180,7 +183,7 @@ void
xwrite(int argc, char **argv)
{
char buf[1024];
- int n;
+ int n, did;
Fid *fid;
ARGBEGIN{
t@@ -191,10 +194,17 @@ xwrite(int argc, char **argv)
if(argc != 1)
usage();
+ did = 0;
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)
sysfatal("write error: %r");
+ }
+ if(n == 0 && !did){
+ if(fswrite(fid, buf, 0) != 0)
+ sysfatal("write error: %r");
+ }
if(n < 0)
sysfatal("read error: %r");
exits(0);