Hello community,

here is the log from the commit of package reptyr for openSUSE:Factory checked 
in at 2013-12-23 12:33:00
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/reptyr (Old)
 and      /work/SRC/openSUSE:Factory/.reptyr.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "reptyr"

Changes:
--------
--- /work/SRC/openSUSE:Factory/reptyr/reptyr.changes    2012-12-19 
13:22:19.000000000 +0100
+++ /work/SRC/openSUSE:Factory/.reptyr.new/reptyr.changes       2013-12-23 
12:33:02.000000000 +0100
@@ -1,0 +2,11 @@
+Fri Dec 20 18:49:10 UTC 2013 - [email protected]
+
+- Update to version 0.5:
+  + Add an early check and error if attaching a process with
+    children.
+- Changes from version 0.4:
+  + Add support for scripting with the -l flag.
+  + Add a French translation of the man page.
+  + Add a -V flag.
+
+-------------------------------------------------------------------

Old:
----
  reptyr-0.3dev_git20120325.tar.bz2

New:
----
  reptyr-0.5.tar.bz2

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ reptyr.spec ++++++
--- /var/tmp/diff_new_pack.YLjYWJ/_old  2013-12-23 12:33:02.000000000 +0100
+++ /var/tmp/diff_new_pack.YLjYWJ/_new  2013-12-23 12:33:02.000000000 +0100
@@ -1,7 +1,7 @@
 #
 # spec file for package reptyr
 #
-# Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany.
+# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -17,7 +17,7 @@
 
 
 Name:           reptyr
-Version:        0.3dev_git20120325
+Version:        0.5
 Release:        0
 Summary:        A tool for "re-ptying" programs
 License:        MIT

++++++ reptyr-0.3dev_git20120325.tar.bz2 -> reptyr-0.5.tar.bz2 ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/reptyr-0.3dev_git20120325/ChangeLog 
new/reptyr-0.5/ChangeLog
--- old/reptyr-0.3dev_git20120325/ChangeLog     2012-04-26 14:09:44.000000000 
+0200
+++ new/reptyr-0.5/ChangeLog    2013-06-05 23:51:32.000000000 +0200
@@ -1,3 +1,11 @@
+* 0.5 (Jun 5, 2013)
+ - Add an early check and error if attaching a process with children.
+
+* 0.4 (Aug 16, 2012)
+ - Add support for scripting with the -l flag.
+ - Add a French translation of the man page
+ - Add a -V flag
+
 * 0.3 (May 27, 2011)
  - Add support for attaching 32-bit programs on x86_64.
  - Fix a bug on ARM.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/reptyr-0.3dev_git20120325/attach.c 
new/reptyr-0.5/attach.c
--- old/reptyr-0.3dev_git20120325/attach.c      2012-04-26 14:09:44.000000000 
+0200
+++ new/reptyr-0.5/attach.c     2013-06-05 23:51:32.000000000 +0200
@@ -73,6 +73,23 @@
     return 0;
 }
 
+int read_proc_stat(pid_t pid, struct proc_stat *out) {
+    char stat_path[PATH_MAX];
+    int statfd;
+    int err;
+
+    snprintf(stat_path, sizeof stat_path, "/proc/%d/stat", pid);
+    statfd = open(stat_path, O_RDONLY);
+    if (statfd < 0) {
+        error("Unable to open %s: %s", stat_path, strerror(errno));
+        return -statfd;
+    }
+
+    err = parse_proc_stat(statfd, out);
+    close(statfd);
+    return err;
+}
+
 static void do_unmap(struct ptrace_child *child, child_addr_t addr, unsigned 
long len) {
     if (addr == (unsigned long)-1)
         return;
@@ -263,11 +280,11 @@
 
 int copy_tty_state(pid_t pid, const char *pty) {
     char buf[PATH_MAX];
-    int fd, err = 0;
+    int fd, err = EINVAL;
     struct termios tio;
     int i;
 
-    for (i = 0; i < 3; i++) {
+    for (i = 0; i < 3 && err; i++) {
         err = 0;
         snprintf(buf, sizeof buf, "/proc/%d/fd/%d", pid, i);
 
@@ -300,6 +317,54 @@
     return -err;
 }
 
+int check_pgroup(pid_t target) {
+    pid_t pg;
+    DIR *dir;
+    struct dirent *d;
+    pid_t pid;
+    char *p;
+    int err = 0;
+    struct proc_stat pid_stat;
+
+    debug("Checking for problematic process group members...");
+
+    pg = getpgid(target);
+    if (pg < 0) {
+        error("Unable to get pgid (does process %d exist?)", (int)target);
+        return pg;
+    }
+
+    if ((dir = opendir("/proc/")) == NULL)
+        return errno;
+
+    while ((d = readdir(dir)) != NULL) {
+        if (d->d_name[0] == '.') continue;
+        pid = strtol(d->d_name, &p, 10);
+        if (*p) continue;
+        if (pid == target) continue;
+        if (getpgid(pid) == pg) {
+            /*
+             * We are actually being somewhat overly-conservative here
+             * -- if pid is a child of target, and has not yet called
+             * execve(), reptyr's setpgid() strategy may suffice. That
+             * is a fairly rare case, and annoying to check for, so
+             * for now let's just bail out.
+             */
+            if ((err = read_proc_stat(pid, &pid_stat))) {
+                memcpy(pid_stat.comm, "???", 4);
+            }
+            error("Process %d (%.*s) shares %d's process group. Unable to 
attach.\n"
+                  "(This most commonly means that %d has a suprocesses).",
+                  (int)pid, TASK_COMM_LENGTH, pid_stat.comm, (int)target, 
(int)target);
+            err = EINVAL;
+            goto out;
+        }
+    }
+ out:
+    closedir(dir);
+    return err;
+}
+
 int attach_child(pid_t pid, const char *pty, int force_stdio) {
     struct ptrace_child child;
     unsigned long scratch_page = -1;
@@ -310,6 +375,10 @@
     char stat_path[PATH_MAX];
     long mmap_syscall;
 
+    if ((err = check_pgroup(pid))) {
+        return err;
+    }
+
     if ((err = copy_tty_state(pid, pty))) {
         if (err == ENOTTY && !force_stdio) {
             error("Target is not connected to a terminal.\n"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/reptyr-0.3dev_git20120325/reptyr.1 
new/reptyr-0.5/reptyr.1
--- old/reptyr-0.3dev_git20120325/reptyr.1      2012-04-26 14:09:44.000000000 
+0200
+++ new/reptyr-0.5/reptyr.1     2013-06-05 23:51:32.000000000 +0200
@@ -6,7 +6,7 @@
 .B reptyr
 .I PID
 
-.B reptyr \-l
+.B reptyr \-l|\-L [COMMAND [ARGS]]
 
 .SH DESCRIPTION
 
@@ -22,7 +22,6 @@
 .B reptyr
 works by attaching to the target program using
 .BR ptrace (2),
-
 redirecting relevant file descriptors, and changing the program's controlling
 terminal (See
 .BR tty (4))
@@ -46,7 +45,7 @@
 
 .SH OPTIONS
 
-.B \-l
+.B \-l, \-L [COMMAND [ARGS]]
 .IP
 Instead of attaching to a new process, create a new pty pair, proxy the master
 end to the current terminal, and then print the name of the slave pty. This can
@@ -54,6 +53,24 @@
 .B gdb\'s
 .I set inferior-tty
 option.
+
+If an optional
+.B COMMAND
+and
+.B ARGS
+are passed in conjunction with
+.B -l,
+that command will be executed as a child of
+.B reptyr
+with the
+.B REPTYR_PTY
+environment variable set to the name of the slave pty. If
+.B -L
+is used instead of
+.B -l,
+then fds 0-2 of the child will also be redirected to point to the
+slave, and the child will be run in a fresh session with the slave as
+its controlling terminal.
 .LP
 
 .B \-s
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/reptyr-0.3dev_git20120325/reptyr.c 
new/reptyr-0.5/reptyr.c
--- old/reptyr-0.3dev_git20120325/reptyr.c      2012-04-26 14:09:44.000000000 
+0200
+++ new/reptyr-0.5/reptyr.c     2013-06-05 23:51:32.000000000 +0200
@@ -154,8 +154,11 @@
 
 void usage(char *me) {
     fprintf(stderr, "Usage: %s [-s] PID\n", me);
-    fprintf(stderr, "       %s -l\n", me);
+    fprintf(stderr, "       %s -l|-L [COMMAND [ARGS]]\n", me);
     fprintf(stderr, "  -l    Create a new pty pair and print the name of the 
slave.\n");
+    fprintf(stderr, "           if there are command-line arguments after 
-l\n");
+    fprintf(stderr, "           they are executed with REPTYR_PTY set to path 
of pty.\n");
+    fprintf(stderr, "  -L    Like '-l', but also redirect the child's stdio to 
the slave.\n");
     fprintf(stderr, "  -s    Attach fds 0-2 on the target, even if it is not 
attached to a tty.\n");
     fprintf(stderr, "  -h    Print this help message and exit.\n");
     fprintf(stderr, "  -v    Print the version number and exit.\n");
@@ -188,6 +191,7 @@
     int arg = 1;
     int do_attach = 1;
     int force_stdio = 0;
+    int unattached_script_redirection = 0;
 
     if (argc < 2) {
         usage(argv[0]);
@@ -201,6 +205,10 @@
         case 'l':
             do_attach = 0;
             break;
+        case 'L':
+            do_attach = 0;
+            unattached_script_redirection = 1;
+            break;
         case 's':
             arg++;
             force_stdio = 1;
@@ -245,6 +253,22 @@
         }
     } else {
         printf("Opened a new pty: %s\n", ptsname(pty));
+        fflush(stdout);
+        if (argc > 2) {
+            if(!fork()) {
+                setenv("REPTYR_PTY", ptsname(pty), 1);
+                if (unattached_script_redirection) {
+                    int f;
+                    setpgid(0, getppid());
+                    setsid();
+                    f = open(ptsname(pty), O_RDONLY, 0); dup2(f, 0);           
 close(f);
+                    f = open(ptsname(pty), O_WRONLY, 0); dup2(f, 1); 
dup2(f,2); close(f);
+                }
+                close(pty);
+                execvp(argv[2], argv+2);
+                exit(1);
+            }
+        }
     }
 
     setup_raw(&saved_termios);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/reptyr-0.3dev_git20120325/reptyr.h 
new/reptyr-0.5/reptyr.h
--- old/reptyr-0.3dev_git20120325/reptyr.h      2012-04-26 14:09:44.000000000 
+0200
+++ new/reptyr-0.5/reptyr.h     2013-06-05 23:51:32.000000000 +0200
@@ -20,7 +20,7 @@
  * THE SOFTWARE.
  */
 
-#define REPTYR_VERSION "0.3dev"
+#define REPTYR_VERSION "0.5"
 
 int attach_child(pid_t pid, const char *pty, int force_stdio);
 #define __printf __attribute__((format(printf, 1, 2)))

-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to