mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-29 00:11:08 +02:00
helpers: add run_pty() function
This runs an external command inside a pty. Running inside a pty,
external commands using stdio(3) will disable stdout buffering when
running from a terminal, which is often desirable.
Origin commit data
------------------
Commit: 85bb568d02
Author: Stefan Seyfried <seife@tuxbox-git.slipkontur.de>
Date: 2017-01-29 (Sun, 29 Jan 2017)
This commit is contained in:
committed by
vanhofen
parent
43a9c2f71d
commit
d7d787a05c
@@ -123,6 +123,7 @@ neutrino_LDADD = \
|
|||||||
$(PUGIXML_LIBS) \
|
$(PUGIXML_LIBS) \
|
||||||
-ldvbsi++ \
|
-ldvbsi++ \
|
||||||
-ljpeg \
|
-ljpeg \
|
||||||
|
-lutil \
|
||||||
-lOpenThreads \
|
-lOpenThreads \
|
||||||
-lrt -lpthread
|
-lrt -lpthread
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
License: GPL
|
License: GPL
|
||||||
|
|
||||||
(C) 2012-2013 the neutrino-hd developers
|
(C) 2012-2013 the neutrino-hd developers
|
||||||
(C) 2012-2015 Stefan Seyfried
|
(C) 2012-2017 Stefan Seyfried
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <pty.h> /* forkpty*/
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -220,6 +221,22 @@ FILE* my_popen( pid_t& pid, const char *cmdstring, const char *type)
|
|||||||
}
|
}
|
||||||
return(fp);
|
return(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int run_pty(pid_t &pid, const char *cmdstring)
|
||||||
|
{
|
||||||
|
int master = -1;
|
||||||
|
if ((pid = forkpty(&master, NULL, NULL, NULL)) < 0)
|
||||||
|
return -1;
|
||||||
|
else if (pid == 0) {
|
||||||
|
int maxfd = getdtablesize();
|
||||||
|
for(int i = 3; i < maxfd; i++)
|
||||||
|
close(i);
|
||||||
|
execl("/bin/sh", "sh", "-c", cmdstring, (char *)0);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
return master;
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
int mkdirhier(const char *pathname, mode_t mode)
|
int mkdirhier(const char *pathname, mode_t mode)
|
||||||
{
|
{
|
||||||
|
@@ -41,6 +41,7 @@ int my_system(const char * cmd);
|
|||||||
int my_system(int argc, const char *arg, ...); /* argc is number of arguments including command */
|
int my_system(int argc, const char *arg, ...); /* argc is number of arguments including command */
|
||||||
|
|
||||||
FILE* my_popen( pid_t& pid, const char *cmdstring, const char *type);
|
FILE* my_popen( pid_t& pid, const char *cmdstring, const char *type);
|
||||||
|
int run_pty(pid_t &pid, const char *cmdstring);
|
||||||
|
|
||||||
int safe_mkdir(const char * path);
|
int safe_mkdir(const char * path);
|
||||||
inline int safe_mkdir(std::string path) { return safe_mkdir(path.c_str()); }
|
inline int safe_mkdir(std::string path) { return safe_mkdir(path.c_str()); }
|
||||||
|
Reference in New Issue
Block a user