How do I change the "[remote detached]" message in GNU Screen - gnu

When I remote detach a screen session and connect to it myself (screen -r -d), I see the following on the detached session.
[remote detached]
Is it possible to change this message?

It's hard-coded in the screen source (line: 1745 of screen.c in Screen v 4.0.3):
#ifdef REMOTE_DETACH
case D_REMOTE:
AddStr("[remote detached]\r\n");
sign = SIG_BYE;
break;
#endif
You can try editing that part and recompiling the source.

Related

Where the "g_debug" output in GDM source code?

I want to know how gdm works, so I read the gdm source code. I saw a lot of g_debug output in the source code like this:
case SIGUSR1:
g_debug ("Got USR1 signal");
/* FIXME:
* Play with log levels or something
*/
ret = TRUE;
gdm_log_toggle_debug ();
break;
But I want to know where I can find the g_debug output.
You have to set the G_DEBUG environment variable to make GLib print out the debugging information.
Check the values in the documentation for Running and Debugging GLib Applications.
In Fedora 20, you can modify the gdm configuration file, /etc/gdm/custom.conf then add the following.
[debug]
Enable=True
Gesture=True
Then you can view the logs by typing journalctl -lr in the terminal.

Create window into screen

Is there a way to list all window names and depending on the result, creating a new window with a specific name into this (running) session.
How to create a new screen session with assigned window names is documented in the man pages, but i could find information about a solution to the problem above.
From outside the screen session, I don't think so.
But if you are starting from inside, in one of the windows of the right screen session, then yes:
for window_name in foo bar baz quux ; do ## ...
screen -t $window_name
done
You can even get fancy and run some initial commands in each window! This snipped of copy-paste bash helps me get back to work quickly after a reboot. Once I've started the screen session:
for n in $(seq 1 8) ; do ## ...
screen -t proj_$n bash -c "cd /src/foo/proj_$n*/ ;"\
' eval `set_proj_env_vars.sh` ; svn status ; make clean ; make ;'\
' exec bash --login'
done
...and as a great side effect the screen windows are numbered for the various checkouts, where each one can be working on a different bug/feature. Overkill? Totally! But it's a fun hack.

Displaying a window's user in GNU screen's hardstatus

I'm looking for a way to display the active user for each window in a GNU screen session in its the hardstatus line.
Example
I have the following windows open
Window 0 - user1#localmachine
Window 1 - user1#localmachine
Window 2 - user1#localmachine SSH to user2#remotemachine
At the moment the hardstatus is:
0$ something [user1] 1$ something [user1] 2$ something [user2]
Where something [username] is typed in manually.
Is there any way to automatically display the windows current user?
You can use an escape sequence to set the window title, if that's what you want:
echo -e '\033k'$USER#$HOSTNAME'\033\\'
Just add this line to your .bashrc or similar file.

Execute shell commands using popen in c++

I need to be able to execute some shell commands such as moving to the right directory where I have some files I need to decode and then decoding them using another command. I read some stuff about using popen but I didnt really understand how to use it for executing multiple commands.
Any pointers will be greatly appreciated :)
Thanks
FILE *pf;
char command[150];
char data[512];
// Execute a process listing
sprintf(command, "cd");
pf = _popen(command,"r");
sprintf(command, "cd Test_copy");
pf = _popen(command,"r"); */
sprintf(command, "java -jar Tool.jar -b x.fit x.csv");
pf = _popen(command,"r");
if(!pf){
fprintf(stderr, "Could not open pipe for output.\n");
return;
}
// Grab data from process execution
fgets(data, 512 , pf);
// Print grabbed data to the screen.
fprintf(stdout, "-%s-\n",data);
if (_pclose(pf) != 0)
fprintf(stderr," Error: Failed to close command stream \n");
Use ShellExecute to play with files (open with default application etc.). Use system to run shell commands.
No, don't. That would be like using a sledgehammer to knock on a door. Furthermore, it is "evil": http://www.cplusplus.com/forum/articles/11153/

linux: getting umask of an already running process?

How can I check the umask of a program which is currently running?
[update: another process, not the current process.]
You can attach gdb to a running process and then call umask in the debugger:
(gdb) attach <your pid>
...
(gdb) call umask(0)
[Switching to Thread -1217489200 (LWP 11037)]
$1 = 18 # this is the umask
(gdb) call umask(18) # reset umask
$2 = 0
(gdb)
(note: 18 corresponds to a umask of O22 in this example)
This suggests that there may be a really ugly way to get the umask using ptrace.
Beginning with Linux kernel 4.7, the umask is available in /proc/<pid>/status.
From the GNU C Library manual:
Here is an example showing how to read the mask with umask
without changing it permanently:
mode_t
read_umask (void)
{
mode_t mask = umask (0);
umask (mask);
return mask;
}
However, it is better to use getumask if you just want to read
the mask value, because it is reentrant (at least if you use the
GNU operating system).
getumask is glibc-specific, though. So if you value portability, then the non-reentrant solution is the only one there is.
Edit: I've just grepped for ->umask all through the Linux source code. There is nowhere that will get you the umask of a different process. Also, there is no getumask; apparently that's a Hurd-only thing.
If you're the current process, you can write a file to /tmp and check its setting. A better solution is to call umask(3) passing zero - the function returns the setting prior to the call - and then reset it back by passing that value back into umask.
The umask for another process doesn't seem to be exposed.
A colleague just showed me this command line pattern for this. I always have emacs running, so that's in the example below. The perl is my contribution:
sudo gdb --pid=$(pgrep emacs) --batch -ex 'call/o umask(0)' -ex 'call umask($1)' 2> /dev/null | perl -ne 'print("$1\n")if(/^\$1 = (\d+)$/)'

Resources