]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: move two more terminal-related calls into terminal-util.[ch]
authorLennart Poettering <lennart@poettering.net>
Wed, 7 Oct 2015 20:45:48 +0000 (22:45 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 8 Oct 2015 10:49:59 +0000 (12:49 +0200)
src/basic/terminal-util.c
src/basic/terminal-util.h
src/basic/util.c
src/basic/util.h
src/machine/machine-dbus.h
src/machine/machine.c
src/run/run.c

index 22ee6ad83fd7cf1e617dd1d639f777fd292ff5df..50a86a331c4bd24c5db6ab775a77f04af0a3318e 100644 (file)
@@ -1054,6 +1054,33 @@ int get_ctty(pid_t pid, dev_t *_devnr, char **r) {
         return 0;
 }
 
+int ptsname_malloc(int fd, char **ret) {
+        size_t l = 100;
+
+        assert(fd >= 0);
+        assert(ret);
+
+        for (;;) {
+                char *c;
+
+                c = new(char, l);
+                if (!c)
+                        return -ENOMEM;
+
+                if (ptsname_r(fd, c, l) == 0) {
+                        *ret = c;
+                        return 0;
+                }
+                if (errno != ERANGE) {
+                        free(c);
+                        return -errno;
+                }
+
+                free(c);
+                l *= 2;
+        }
+}
+
 int ptsname_namespace(int pty, char **ret) {
         int no = -1, r;
 
@@ -1072,3 +1099,56 @@ int ptsname_namespace(int pty, char **ret) {
 
         return 0;
 }
+
+int openpt_in_namespace(pid_t pid, int flags) {
+        _cleanup_close_ int pidnsfd = -1, mntnsfd = -1, usernsfd = -1, rootfd = -1;
+        _cleanup_close_pair_ int pair[2] = { -1, -1 };
+        siginfo_t si;
+        pid_t child;
+        int r;
+
+        assert(pid > 0);
+
+        r = namespace_open(pid, &pidnsfd, &mntnsfd, NULL, &usernsfd, &rootfd);
+        if (r < 0)
+                return r;
+
+        if (socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) < 0)
+                return -errno;
+
+        child = fork();
+        if (child < 0)
+                return -errno;
+
+        if (child == 0) {
+                int master;
+
+                pair[0] = safe_close(pair[0]);
+
+                r = namespace_enter(pidnsfd, mntnsfd, -1, usernsfd, rootfd);
+                if (r < 0)
+                        _exit(EXIT_FAILURE);
+
+                master = posix_openpt(flags|O_NOCTTY|O_CLOEXEC);
+                if (master < 0)
+                        _exit(EXIT_FAILURE);
+
+                if (unlockpt(master) < 0)
+                        _exit(EXIT_FAILURE);
+
+                if (send_one_fd(pair[1], master, 0) < 0)
+                        _exit(EXIT_FAILURE);
+
+                _exit(EXIT_SUCCESS);
+        }
+
+        pair[1] = safe_close(pair[1]);
+
+        r = wait_for_terminate(child, &si);
+        if (r < 0)
+                return r;
+        if (si.si_code != CLD_EXITED || si.si_status != EXIT_SUCCESS)
+                return -EIO;
+
+        return receive_one_fd(pair[0], 0);
+}
index da2a5b88976cc5579487e5f0c2110dac6a04a229..050d0524a560eb3c4e6cf2300b9226d26bef5d92 100644 (file)
@@ -120,4 +120,7 @@ int get_ctty(pid_t, dev_t *_devnr, char **r);
 int getttyname_malloc(int fd, char **r);
 int getttyname_harder(int fd, char **r);
 
+int ptsname_malloc(int fd, char **ret);
 int ptsname_namespace(int pty, char **ret);
+
+int openpt_in_namespace(pid_t pid, int flags);
index f845e2dabbbdc9ad7126c05e605b078066311c66..ca5e4befa06587628d66496713b4cd850e3a71ef 100644 (file)
@@ -6087,86 +6087,6 @@ int free_and_strdup(char **p, const char *s) {
         return 1;
 }
 
-int ptsname_malloc(int fd, char **ret) {
-        size_t l = 100;
-
-        assert(fd >= 0);
-        assert(ret);
-
-        for (;;) {
-                char *c;
-
-                c = new(char, l);
-                if (!c)
-                        return -ENOMEM;
-
-                if (ptsname_r(fd, c, l) == 0) {
-                        *ret = c;
-                        return 0;
-                }
-                if (errno != ERANGE) {
-                        free(c);
-                        return -errno;
-                }
-
-                free(c);
-                l *= 2;
-        }
-}
-
-int openpt_in_namespace(pid_t pid, int flags) {
-        _cleanup_close_ int pidnsfd = -1, mntnsfd = -1, usernsfd = -1, rootfd = -1;
-        _cleanup_close_pair_ int pair[2] = { -1, -1 };
-        siginfo_t si;
-        pid_t child;
-        int r;
-
-        assert(pid > 0);
-
-        r = namespace_open(pid, &pidnsfd, &mntnsfd, NULL, &usernsfd, &rootfd);
-        if (r < 0)
-                return r;
-
-        if (socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) < 0)
-                return -errno;
-
-        child = fork();
-        if (child < 0)
-                return -errno;
-
-        if (child == 0) {
-                int master;
-
-                pair[0] = safe_close(pair[0]);
-
-                r = namespace_enter(pidnsfd, mntnsfd, -1, usernsfd, rootfd);
-                if (r < 0)
-                        _exit(EXIT_FAILURE);
-
-                master = posix_openpt(flags|O_NOCTTY|O_CLOEXEC);
-                if (master < 0)
-                        _exit(EXIT_FAILURE);
-
-                if (unlockpt(master) < 0)
-                        _exit(EXIT_FAILURE);
-
-                if (send_one_fd(pair[1], master, 0) < 0)
-                        _exit(EXIT_FAILURE);
-
-                _exit(EXIT_SUCCESS);
-        }
-
-        pair[1] = safe_close(pair[1]);
-
-        r = wait_for_terminate(child, &si);
-        if (r < 0)
-                return r;
-        if (si.si_code != CLD_EXITED || si.si_status != EXIT_SUCCESS)
-                return -EIO;
-
-        return receive_one_fd(pair[0], 0);
-}
-
 ssize_t fgetxattrat_fake(int dirfd, const char *filename, const char *attribute, void *value, size_t size, int flags) {
         char fn[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1];
         _cleanup_close_ int fd = -1;
index 034410b8a8c05c82de8e1f4801d0b0dbd025d4df..79c7ad1b39918967b60c5a8c63bf760b8b6bec57 100644 (file)
@@ -891,10 +891,6 @@ union inotify_event_buffer {
 
 #define laccess(path, mode) faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW)
 
-int ptsname_malloc(int fd, char **ret);
-
-int openpt_in_namespace(pid_t pid, int flags);
-
 ssize_t fgetxattrat_fake(int dirfd, const char *filename, const char *attribute, void *value, size_t size, int flags);
 
 int fd_setcrtime(int fd, usec_t usec);
index 38b46ad936f62b82ba3f00403ee4979b76ec54b1..194e680e05b67c970510268ff96a544db8b3448a 100644 (file)
@@ -23,6 +23,8 @@
 
 #include "sd-bus.h"
 
+#include "machine.h"
+
 extern const sd_bus_vtable machine_vtable[];
 
 char *machine_bus_path(Machine *s);
index b52ecd015c3cbfcfb6d4ca9a91d052762a399a54..0f1942d1f4671dbe96b96eb4cc5ff4729739844e 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include <errno.h>
 #include <string.h>
 #include <unistd.h>
-#include <errno.h>
 
 #include "sd-messages.h"
 
-#include "util.h"
-#include "mkdir.h"
-#include "hashmap.h"
+#include "bus-error.h"
+#include "bus-util.h"
 #include "fileio.h"
+#include "formats-util.h"
+#include "hashmap.h"
+#include "mkdir.h"
 #include "special.h"
+#include "terminal-util.h"
 #include "unit-name.h"
-#include "bus-util.h"
-#include "bus-error.h"
-#include "machine.h"
+#include "util.h"
 #include "machine-dbus.h"
-#include "formats-util.h"
+#include "machine.h"
 
 Machine* machine_new(Manager *manager, MachineClass class, const char *name) {
         Machine *m;
index bb18dd4383e19592420d4751f4cb0df8aa58a673..1f89bfd6fb8f3dacc9854e0beeb8fcdfc3df5b4e 100644 (file)
@@ -36,6 +36,7 @@
 #include "signal-util.h"
 #include "spawn-polkit-agent.h"
 #include "strv.h"
+#include "terminal-util.h"
 #include "unit-name.h"
 
 static bool arg_ask_password = true;