From f04882c76d0d23a35942e736e89ef19268f541b5 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Sat, 7 Feb 2009 20:00:26 -0500 Subject: Copyright for 2009 --- src/socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/socket.c') diff --git a/src/socket.c b/src/socket.c index 48e8ad9..acdd7d1 100644 --- a/src/socket.c +++ b/src/socket.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2008 +/* Copyright (c) 2008, 2009 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de) * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de) * Micah Cowan (micah@cowan.name) -- cgit v1.2.1 From 52a0417cf7fe630c60f730a7dd706394c8e55499 Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Fri, 24 Jul 2009 12:05:25 +0200 Subject: - fix reattach segfault when size is too small for windowlist - add focus up/down/left/right commands --- src/socket.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/socket.c') diff --git a/src/socket.c b/src/socket.c index acdd7d1..7832832 100644 --- a/src/socket.c +++ b/src/socket.c @@ -1378,9 +1378,11 @@ struct msg *m; if (!AclCheckPermCmd(D_user, ACL_EXEC, &comms[RC_WINDOWLIST])) #endif { + struct display *olddisplay = display; flayer = D_forecv->c_layer; display_wlist(1, WLIST_NUM, (struct win *)0); noshowwin = 1; + display = olddisplay; /* display_wlist can change display */ } } Activate(0); -- cgit v1.2.1 From 8147d08647d59aba7accb748c42db2aba3f31bc4 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Wed, 30 Sep 2009 15:54:19 -0400 Subject: 'screen -Q ' to get back results. This is the just the start of querying an existing session. The goal is to allow something like "windows=`screen -Q windows`" in a bash script to get back the results from the 'windows' command. Most of the framework is done. Now the commands need to be updated to specially deal with the queries. --- src/socket.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'src/socket.c') diff --git a/src/socket.c b/src/socket.c index 7832832..965a7d0 100644 --- a/src/socket.c +++ b/src/socket.c @@ -1156,14 +1156,58 @@ ReceiveMsg() FinishDetach(&m); break; #endif + case MSG_QUERY: + /* Reset error buffer */ + /* Reset output buffer */ + /* FALLTHROUGH */ case MSG_COMMAND: DoCommandMsg(&m); + if (m.type == MSG_QUERY) + { + char *oldSockPath = SaveStr(SockPath); + strcpy(SockPath, m.m.command.writeback); + int s = MakeClientSocket(0); + strcpy(SockPath, oldSockPath); + Free(oldSockPath); + if (s >= 0) + { + write(s, "So ...", 7); + close(s); + } + Kill(m.m.command.apid, SIGCONT); /* Send SIG_BYE if an error happened, instead */ + } break; default: Msg(0, "Invalid message (type %d).", m.type); } } +void +ReceiveRaw(s) +int s; +{ + char rd[256]; + int len = 0; +#ifdef NAMEDPIPE + if (fcntl(s, F_SETFL, 0) == -1) + Panic(errno, "BLOCK fcntl"); +#else + struct sockaddr_un a; + len = sizeof(a); + if ((s = accept(s, (struct sockaddr *) &a, (void *)&len)) < 0) + { + Msg(errno, "accept"); + return; + } +#endif + while ((len = read(s, rd, 255)) > 0) + { + rd[len] = 0; + printf("%s", rd); + } + close(s); +} + #if defined(_SEQUENT_) && !defined(NAMEDPIPE) #undef connect /* @@ -1590,12 +1634,16 @@ struct msg *mp; if (fc != fullcmd) *--fc = 0; if (Parse(fullcmd, fc - fullcmd, args, argl) <= 0) - return; + { + /* XXX: Return some useful message back if MSG_QUERY */ + return; + } #ifdef MULTIUSER user = *FindUserPtr(mp->m.attach.auser); if (user == 0) { Msg(0, "Unknown user %s tried to send a command!", mp->m.attach.auser); + /* XXX: Return some useful message back if MSG_QUERY */ return; } #else @@ -1605,6 +1653,7 @@ struct msg *mp; if (user->u_password && *user->u_password) { Msg(0, "User %s has a password, cannot use -X option.", mp->m.attach.auser); + /* XXX: Return some useful message back if MSG_QUERY */ return; } #endif -- cgit v1.2.1 From ce4d17091290ddadf21275077f4158b222b4e426 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Thu, 17 Dec 2009 16:03:34 -0500 Subject: Allow attaching to a session whose name starts with digits. Fixes debian bug#549272. --- src/socket.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/socket.c') diff --git a/src/socket.c b/src/socket.c index 7832832..68a4258 100644 --- a/src/socket.c +++ b/src/socket.c @@ -181,8 +181,21 @@ char *match; if (strncmp(match, "tty", 3) && strncmp(n, "tty", 3) == 0) n += 3; if (strncmp(match, n, matchlen)) - continue; - cmatch = (*(n + matchlen) == 0); + { + if (n == name && *match > '0' && *match <= '9') + { + while (*n >= '0' && *n <= '9') + n++; + if (*n == '.') + n++; + if (strncmp(match, n, matchlen)) + continue; + } + else + continue; + } + else + cmatch = (*(n + matchlen) == 0); debug1(" -> matched %s\n", match); } sprintf(SockPath + sdirlen, "/%s", name); -- cgit v1.2.1 From f33e5cdecb7bf3b6ae8e4a5c0ca394dd5a06a416 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Tue, 26 Jan 2010 15:15:24 -0500 Subject: Increase the max-window limit. The limit can be increased using the 'maxwin' command. There is still an upper-limit of 2048 windows. --- src/socket.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/socket.c') diff --git a/src/socket.c b/src/socket.c index 68a4258..cd7ef56 100644 --- a/src/socket.c +++ b/src/socket.c @@ -67,13 +67,14 @@ extern int ServerSocket, real_uid, real_gid, eff_uid, eff_gid; extern int dflag, iflag, rflag, lsflag, quietflag, wipeflag, xflag; extern char *attach_tty, *LoginName, HostName[]; extern struct display *display, *displays; -extern struct win *fore, *wtab[], *console_window, *windows; +extern struct win *fore, **wtab, *console_window, *windows; extern struct layer *flayer; extern struct layout *layout_attach, *layout_last, layout_last_marker; extern struct NewWindow nwin_undef; #ifdef MULTIUSER extern char *multi; #endif +extern int maxwin; extern char *getenv(); @@ -736,7 +737,7 @@ struct msg *mp; if (*buf) nwin.aka = buf; num = atoi(p); - if (num < 0 || num > MAXWIN - 1) + if (num < 0 || num > maxwin - 1) num = 0; nwin.StartAt = num; p += l + 1; -- cgit v1.2.1 From b040667633ecccb582426536936f07c8e005c87b Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Fri, 12 Feb 2010 16:26:16 -0500 Subject: Put in some flags to suppress messages from commands. A command name can be prefixed by '@' to suppress the error messages, and by '-' to suppress the normal messages. The flags are currently parsed, but not acted upon. --- src/socket.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/socket.c') diff --git a/src/socket.c b/src/socket.c index cd7ef56..a174b72 100644 --- a/src/socket.c +++ b/src/socket.c @@ -1377,6 +1377,7 @@ struct msg *m; char *na = 0; newscreen.nr = RC_SCREEN; newscreen.args = &na; + newscreen.quiet = 0; DoAction(&newscreen, -1); } else -- cgit v1.2.1 From 929be520ad026011ac98420f4a56fa93dff06899 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Tue, 16 Feb 2010 11:00:58 -0500 Subject: Complete the query-response system. Some commands now can be queried from a remote session using the '-Q' flag, e.g. 'screen -Q windows'. The commands will send the response to the stdout of the querying process. If there was an error in the command, then the querying process will exit with a non-zero status. The commands that can be queried now are: echo info lastmsg time title windows --- src/socket.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/socket.c') diff --git a/src/socket.c b/src/socket.c index 08b545f..70b57db 100644 --- a/src/socket.c +++ b/src/socket.c @@ -65,6 +65,7 @@ static void AskPassword __P((struct msg *)); extern char *RcFileName, *extra_incap, *extra_outcap; extern int ServerSocket, real_uid, real_gid, eff_uid, eff_gid; extern int dflag, iflag, rflag, lsflag, quietflag, wipeflag, xflag; +extern int queryflag; extern char *attach_tty, *LoginName, HostName[]; extern struct display *display, *displays; extern struct win *fore, **wtab, *console_window, *windows; @@ -1171,12 +1172,6 @@ ReceiveMsg() break; #endif case MSG_QUERY: - /* Reset error buffer */ - /* Reset output buffer */ - /* FALLTHROUGH */ - case MSG_COMMAND: - DoCommandMsg(&m); - if (m.type == MSG_QUERY) { char *oldSockPath = SaveStr(SockPath); strcpy(SockPath, m.m.command.writeback); @@ -1185,12 +1180,20 @@ ReceiveMsg() Free(oldSockPath); if (s >= 0) { - write(s, "So ...", 7); + queryflag = s; + DoCommandMsg(&m); close(s); } - Kill(m.m.command.apid, SIGCONT); /* Send SIG_BYE if an error happened, instead */ + else + queryflag = -1; + + Kill(m.m.command.apid, (queryflag >= 0) ? SIGCONT : SIG_BYE); /* Send SIG_BYE if an error happened */ + queryflag = -1; } break; + case MSG_COMMAND: + DoCommandMsg(&m); + break; default: Msg(0, "Invalid message (type %d).", m.type); } -- cgit v1.2.1 From a889d858d6baae4d6bc2da98bf6ee82e52ad5fbc Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Tue, 16 Feb 2010 13:37:39 -0500 Subject: Error out if a pre-select window is not found. The man-page is updated to show that if the window selected using '-p' cannot be determined with -X or -Q flags, then the command specified will not be executed. Fixes #28783 in savannah. --- src/socket.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/socket.c') diff --git a/src/socket.c b/src/socket.c index 70b57db..9e90564 100644 --- a/src/socket.c +++ b/src/socket.c @@ -1653,7 +1653,7 @@ struct msg *mp; *--fc = 0; if (Parse(fullcmd, fc - fullcmd, args, argl) <= 0) { - /* XXX: Return some useful message back if MSG_QUERY */ + queryflag = -1; return; } #ifdef MULTIUSER @@ -1661,7 +1661,7 @@ struct msg *mp; if (user == 0) { Msg(0, "Unknown user %s tried to send a command!", mp->m.attach.auser); - /* XXX: Return some useful message back if MSG_QUERY */ + queryflag = -1; return; } #else @@ -1670,8 +1670,8 @@ struct msg *mp; #ifdef PASSWORD if (user->u_password && *user->u_password) { - Msg(0, "User %s has a password, cannot use -X option.", mp->m.attach.auser); - /* XXX: Return some useful message back if MSG_QUERY */ + Msg(0, "User %s has a password, cannot use remote commands (using -Q or -X option).", mp->m.attach.auser); + queryflag = -1; return; } #endif @@ -1692,7 +1692,15 @@ struct msg *mp; { int i = -1; if (strcmp(mp->m.command.preselect, "-")) - i = WindowByNoN(mp->m.command.preselect); + { + i = WindowByNoN(mp->m.command.preselect); + if (i < 0 || !wtab[i]) + { + Msg(0, "Could not find pre-select window."); + queryflag = -1; + return; + } + } fore = i >= 0 ? wtab[i] : 0; } else if (!fore) -- cgit v1.2.1 From e01e137673bf09e2897ead3170719c5a2fb1f087 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Tue, 16 Feb 2010 16:29:34 -0500 Subject: Allow expanding the command to full buffer size. Without this, commands like '-Q echo $STY' would fail with error: no space left for variable expansion. --- src/socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/socket.c') diff --git a/src/socket.c b/src/socket.c index 9e90564..0f08d60 100644 --- a/src/socket.c +++ b/src/socket.c @@ -1651,7 +1651,7 @@ struct msg *mp; } if (fc != fullcmd) *--fc = 0; - if (Parse(fullcmd, fc - fullcmd, args, argl) <= 0) + if (Parse(fullcmd, sizeof fullcmd, args, argl) <= 0) { queryflag = -1; return; -- cgit v1.2.1 From 1df022599350ae3882843b772b2bc0869348b894 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Tue, 23 Feb 2010 20:35:03 -0500 Subject: Remove old code. --- src/socket.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/socket.c') diff --git a/src/socket.c b/src/socket.c index 0f08d60..680a150 100644 --- a/src/socket.c +++ b/src/socket.c @@ -49,6 +49,7 @@ #endif #include "extern.h" +#include "list_generic.h" static int CheckPid __P((int)); static void ExecCreate __P((struct msg *)); @@ -1442,9 +1443,9 @@ struct msg *m; { struct display *olddisplay = display; flayer = D_forecv->c_layer; - display_wlist(1, WLIST_NUM, (struct win *)0); + display_windows(1, WLIST_NUM, (struct win *)0); noshowwin = 1; - display = olddisplay; /* display_wlist can change display */ + display = olddisplay; /* display_windows can change display */ } } Activate(0); -- cgit v1.2.1 From 42f59cca30ef4e7a390b283ba02a4a015718fb2e Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Wed, 24 Feb 2010 02:32:23 -0500 Subject: Typo fixes from Trent W Buck. --- src/socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/socket.c') diff --git a/src/socket.c b/src/socket.c index 680a150..9e61816 100644 --- a/src/socket.c +++ b/src/socket.c @@ -451,7 +451,7 @@ MakeServerSocket() if (stat(SockPath, &st) == -1) Panic(errno, "stat"); if ((int)st.st_uid != real_uid) - Panic(0, "Unfortunatelly you are not its owner."); + Panic(0, "Unfortunately you are not its owner."); if ((st.st_mode & 0700) == 0600) Panic(0, "To resume it, use \"screen -r\""); else @@ -543,7 +543,7 @@ MakeServerSocket() if (stat(SockPath, &st) == -1) Panic(errno, "stat"); if (st.st_uid != real_uid) - Panic(0, "Unfortunatelly you are not its owner."); + Panic(0, "Unfortunately you are not its owner."); if ((st.st_mode & 0700) == 0600) Panic(0, "To resume it, use \"screen -r\""); else -- cgit v1.2.1 From 261a022ce947d17471b73a71345c265df9bfe7a4 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Sun, 7 Mar 2010 19:29:39 -0500 Subject: Fix build with -Werror=format-security Some distributions ( mandriva for example ) use -Werror=format-security by default when build C software to try to enhance code quality and prevent security bugs. As the policy is to correct all occurences of the error ( so there is no false positive, nor question about to fix it or not ), a patch that fix the error on gnu screen 4.0.3 have been added to the package. I have rediffed it against latest git snapshot, to be sent upstream. It mainly add "%s" where applicable. --- src/socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/socket.c') diff --git a/src/socket.c b/src/socket.c index 9e61816..9dbf461 100644 --- a/src/socket.c +++ b/src/socket.c @@ -1540,7 +1540,7 @@ struct msg *m; ASSERT(display); pwdata = (struct pwdata *)malloc(sizeof(struct pwdata)); if (!pwdata) - Panic(0, strnomem); + Panic(0, "%s", strnomem); pwdata->l = 0; pwdata->m = *m; D_processinputdata = (char *)pwdata; -- cgit v1.2.1