aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStefan Kangas2021-12-12 06:31:07 +0100
committerStefan Kangas2021-12-12 06:31:07 +0100
commit2d116c432d2a561fac69916d78b7a70dd6144ac7 (patch)
treedd948eabc6fba59704c2a66ea7d97624c86e2228 /src
parent4b29468dbef63f2befd7f67663a11cd5a3009b79 (diff)
parent8a0734329a4faf0b45627763af74222bdd0ec143 (diff)
downloademacs-2d116c432d2a561fac69916d78b7a70dd6144ac7.tar.gz
emacs-2d116c432d2a561fac69916d78b7a70dd6144ac7.zip
Merge from origin/emacs-28
8a0734329a Avoid undefined behavior in 'send-process-region' (Bug#523... 30dd5c9acc Update to Org 9.5.1-25-g9ca3bc a374849926 Fix the DJGPP port
Diffstat (limited to 'src')
-rw-r--r--src/callproc.c27
-rw-r--r--src/fileio.c2
-rw-r--r--src/msdos.c102
-rw-r--r--src/msdos.h2
-rw-r--r--src/process.c20
-rw-r--r--src/thread.h1
6 files changed, 151 insertions, 3 deletions
diff --git a/src/callproc.c b/src/callproc.c
index c949fff4db9..c89628bb0ec 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -25,6 +25,10 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
25#include <sys/types.h> 25#include <sys/types.h>
26#include <unistd.h> 26#include <unistd.h>
27 27
28#ifdef MSDOS
29extern char **environ;
30#endif
31
28#include <sys/file.h> 32#include <sys/file.h>
29#include <fcntl.h> 33#include <fcntl.h>
30 34
@@ -1199,6 +1203,11 @@ static CHILD_SETUP_TYPE
1199child_setup (int in, int out, int err, char **new_argv, char **env, 1203child_setup (int in, int out, int err, char **new_argv, char **env,
1200 const char *current_dir) 1204 const char *current_dir)
1201{ 1205{
1206#ifdef MSDOS
1207 char *pwd_var;
1208 char *temp;
1209 ptrdiff_t i;
1210#endif
1202#ifdef WINDOWSNT 1211#ifdef WINDOWSNT
1203 int cpid; 1212 int cpid;
1204 HANDLE handles[3]; 1213 HANDLE handles[3];
@@ -1251,6 +1260,22 @@ child_setup (int in, int out, int err, char **new_argv, char **env,
1251 exec_failed (new_argv[0], errnum); 1260 exec_failed (new_argv[0], errnum);
1252 1261
1253#else /* MSDOS */ 1262#else /* MSDOS */
1263 i = strlen (current_dir);
1264 pwd_var = xmalloc (i + 5);
1265 temp = pwd_var + 4;
1266 memcpy (pwd_var, "PWD=", 4);
1267 stpcpy (temp, current_dir);
1268
1269 if (i > 2 && IS_DEVICE_SEP (temp[1]) && IS_DIRECTORY_SEP (temp[2]))
1270 {
1271 temp += 2;
1272 i -= 2;
1273 }
1274
1275 /* Strip trailing slashes for PWD, but leave "/" and "//" alone. */
1276 while (i > 2 && IS_DIRECTORY_SEP (temp[i - 1]))
1277 temp[--i] = 0;
1278
1254 pid = run_msdos_command (new_argv, pwd_var + 4, in, out, err, env); 1279 pid = run_msdos_command (new_argv, pwd_var + 4, in, out, err, env);
1255 xfree (pwd_var); 1280 xfree (pwd_var);
1256 if (pid == -1) 1281 if (pid == -1)
@@ -1582,11 +1607,13 @@ emacs_spawn (pid_t *newpid, int std_in, int std_out, int std_err,
1582 signal (SIGPROF, SIG_DFL); 1607 signal (SIGPROF, SIG_DFL);
1583#endif 1608#endif
1584 1609
1610#ifdef subprocesses
1585 /* Stop blocking SIGCHLD in the child. */ 1611 /* Stop blocking SIGCHLD in the child. */
1586 unblock_child_signal (oldset); 1612 unblock_child_signal (oldset);
1587 1613
1588 if (pty_flag) 1614 if (pty_flag)
1589 child_setup_tty (std_out); 1615 child_setup_tty (std_out);
1616#endif
1590 1617
1591 if (std_err < 0) 1618 if (std_err < 0)
1592 std_err = std_out; 1619 std_err = std_out;
diff --git a/src/fileio.c b/src/fileio.c
index 12ece586b83..a0563ccba4b 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -2286,6 +2286,7 @@ permissions. */)
2286 off_t insize = st.st_size; 2286 off_t insize = st.st_size;
2287 ssize_t copied; 2287 ssize_t copied;
2288 2288
2289#ifndef MSDOS
2289 for (newsize = 0; newsize < insize; newsize += copied) 2290 for (newsize = 0; newsize < insize; newsize += copied)
2290 { 2291 {
2291 /* Copy at most COPY_MAX bytes at a time; this is min 2292 /* Copy at most COPY_MAX bytes at a time; this is min
@@ -2300,6 +2301,7 @@ permissions. */)
2300 break; 2301 break;
2301 maybe_quit (); 2302 maybe_quit ();
2302 } 2303 }
2304#endif /* MSDOS */
2303 2305
2304 /* Fall back on read+write if copy_file_range failed, or if the 2306 /* Fall back on read+write if copy_file_range failed, or if the
2305 input is empty and so could be a /proc file. read+write will 2307 input is empty and so could be a /proc file. read+write will
diff --git a/src/msdos.c b/src/msdos.c
index bf058c8aff9..2272aba6fde 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -1874,6 +1874,7 @@ initialize_msdos_display (struct terminal *term)
1874 term->redeem_scroll_bar_hook = 0; 1874 term->redeem_scroll_bar_hook = 0;
1875 term->judge_scroll_bars_hook = 0; 1875 term->judge_scroll_bars_hook = 0;
1876 term->read_socket_hook = &tty_read_avail_input; /* from keyboard.c */ 1876 term->read_socket_hook = &tty_read_avail_input; /* from keyboard.c */
1877 term->defined_color_hook = &tty_defined_color; /* from xfaces.c */
1877} 1878}
1878 1879
1879int 1880int
@@ -3915,6 +3916,50 @@ readlinkat (int fd, char const *name, char *buffer, size_t buffer_size)
3915 return readlink (name, buffer, buffer_size); 3916 return readlink (name, buffer, buffer_size);
3916} 3917}
3917 3918
3919
3920int
3921openat (int fd, const char * path, int oflag, int mode)
3922{
3923 /* Rely on a hack: an open directory is modeled as file descriptor 0,
3924 as in fstatat. FIXME: Add proper support for openat. */
3925 char fullname[MAXPATHLEN];
3926
3927 if (fd != AT_FDCWD)
3928 {
3929 if (strlen (dir_pathname) + strlen (path) + 1 >= MAXPATHLEN)
3930 {
3931 errno = ENAMETOOLONG;
3932 return -1;
3933 }
3934 sprintf (fullname, "%s/%s", dir_pathname, path);
3935 path = fullname;
3936 }
3937
3938 return open (path, oflag, mode);
3939}
3940
3941int
3942fchmodat (int fd, const char *path, mode_t mode, int flags)
3943{
3944 /* Rely on a hack: an open directory is modeled as file descriptor 0,
3945 as in fstatat. FIXME: Add proper support for openat. */
3946 char fullname[MAXPATHLEN];
3947
3948 if (fd != AT_FDCWD)
3949 {
3950 if (strlen (dir_pathname) + strlen (path) + 1 >= MAXPATHLEN)
3951 {
3952 errno = ENAMETOOLONG;
3953 return -1;
3954 }
3955
3956 sprintf (fullname, "%s/%s", dir_pathname, path);
3957 path = fullname;
3958 }
3959
3960 return chmod (path, mode);
3961}
3962
3918char * 3963char *
3919careadlinkat (int fd, char const *filename, 3964careadlinkat (int fd, char const *filename,
3920 char *buffer, size_t buffer_size, 3965 char *buffer, size_t buffer_size,
@@ -3942,6 +3987,63 @@ careadlinkat (int fd, char const *filename,
3942 return buffer; 3987 return buffer;
3943} 3988}
3944 3989
3990int
3991futimens (int fd, const struct timespec times[2])
3992{
3993 struct tm *tm;
3994 struct ftime ft;
3995 time_t t;
3996
3997 block_input ();
3998 if (times[1].tv_sec == UTIME_NOW)
3999 t = time (NULL);
4000 else
4001 t = times[1].tv_sec;
4002
4003 tm = localtime (&t);
4004 ft.ft_tsec = min (29, tm->tm_sec / 2);
4005 ft.ft_min = tm->tm_min;
4006 ft.ft_hour = tm->tm_hour;
4007 ft.ft_day = tm->tm_mday;
4008 ft.ft_month = tm->tm_mon + 1;
4009 ft.ft_year = max (0, tm->tm_year - 80);
4010 unblock_input ();
4011
4012 return setftime (fd, &ft);
4013}
4014
4015int
4016utimensat (int dirfd, const char *pathname,
4017 const struct timespec times[2], int flags)
4018{
4019 int fd, ret;
4020 char fullname[MAXPATHLEN];
4021
4022 /* Rely on a hack: dirfd in its current usage in Emacs is always
4023 AT_FDCWD. */
4024
4025 if (dirfd != AT_FDCWD)
4026 {
4027 if (strlen (dir_pathname) + strlen (pathname) + 1 >= MAXPATHLEN)
4028 {
4029 errno = ENAMETOOLONG;
4030 return -1;
4031 }
4032 sprintf (fullname, "%s/%s", dir_pathname, pathname);
4033 pathname = fullname;
4034 }
4035
4036 fd = open (pathname, O_WRONLY);
4037
4038 if (fd < 0)
4039 return -1;
4040
4041 ret = futimens (fd, times);
4042 close (fd);
4043
4044 return ret;
4045}
4046
3945/* Emulate faccessat(2). */ 4047/* Emulate faccessat(2). */
3946int 4048int
3947faccessat (int dirfd, const char * path, int mode, int flags) 4049faccessat (int dirfd, const char * path, int mode, int flags)
diff --git a/src/msdos.h b/src/msdos.h
index f7d3b0d7029..d58b60ef5df 100644
--- a/src/msdos.h
+++ b/src/msdos.h
@@ -86,6 +86,8 @@ typedef int GC;
86typedef int Pixmap; 86typedef int Pixmap;
87typedef int Display; 87typedef int Display;
88typedef int Window; 88typedef int Window;
89
90#define FRAME_X_DISPLAY(ignored) NULL
89#define PIX_TYPE unsigned long 91#define PIX_TYPE unsigned long
90#define XDISPLAY 92#define XDISPLAY
91 93
diff --git a/src/process.c b/src/process.c
index 483da4d7e4f..76094988f25 100644
--- a/src/process.c
+++ b/src/process.c
@@ -40,7 +40,10 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
40#include <netinet/in.h> 40#include <netinet/in.h>
41#include <arpa/inet.h> 41#include <arpa/inet.h>
42 42
43#endif /* subprocesses */ 43#else
44#define PIPECONN_P(p) false
45#define PIPECONN1_P(p) false
46#endif
44 47
45#ifdef HAVE_SETRLIMIT 48#ifdef HAVE_SETRLIMIT
46# include <sys/resource.h> 49# include <sys/resource.h>
@@ -152,6 +155,7 @@ static bool kbd_is_on_hold;
152 when exiting. */ 155 when exiting. */
153bool inhibit_sentinels; 156bool inhibit_sentinels;
154 157
158#ifdef subprocesses
155union u_sockaddr 159union u_sockaddr
156{ 160{
157 struct sockaddr sa; 161 struct sockaddr sa;
@@ -164,8 +168,6 @@ union u_sockaddr
164#endif 168#endif
165}; 169};
166 170
167#ifdef subprocesses
168
169#ifndef SOCK_CLOEXEC 171#ifndef SOCK_CLOEXEC
170# define SOCK_CLOEXEC 0 172# define SOCK_CLOEXEC 0
171#endif 173#endif
@@ -6536,6 +6538,9 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len,
6536 /* Send this batch, using one or more write calls. */ 6538 /* Send this batch, using one or more write calls. */
6537 ptrdiff_t written = 0; 6539 ptrdiff_t written = 0;
6538 int outfd = p->outfd; 6540 int outfd = p->outfd;
6541 if (outfd < 0)
6542 error ("Output file descriptor of %s is closed",
6543 SDATA (p->name));
6539 eassert (0 <= outfd && outfd < FD_SETSIZE); 6544 eassert (0 <= outfd && outfd < FD_SETSIZE);
6540#ifdef DATAGRAM_SOCKETS 6545#ifdef DATAGRAM_SOCKETS
6541 if (DATAGRAM_CHAN_P (outfd)) 6546 if (DATAGRAM_CHAN_P (outfd))
@@ -8257,9 +8262,13 @@ If optional argument QUERY is `current', ignore OMP_NUM_THREADS.
8257If QUERY is `all', also count processors not available. */) 8262If QUERY is `all', also count processors not available. */)
8258 (Lisp_Object query) 8263 (Lisp_Object query)
8259{ 8264{
8265#ifndef MSDOS
8260 return make_uint (num_processors (EQ (query, Qall) ? NPROC_ALL 8266 return make_uint (num_processors (EQ (query, Qall) ? NPROC_ALL
8261 : EQ (query, Qcurrent) ? NPROC_CURRENT 8267 : EQ (query, Qcurrent) ? NPROC_CURRENT
8262 : NPROC_CURRENT_OVERRIDABLE)); 8268 : NPROC_CURRENT_OVERRIDABLE));
8269#else
8270 return make_fixnum (1);
8271#endif
8263} 8272}
8264 8273
8265#ifdef subprocesses 8274#ifdef subprocesses
@@ -8304,10 +8313,15 @@ open_channel_for_module (Lisp_Object process)
8304{ 8313{
8305 CHECK_PROCESS (process); 8314 CHECK_PROCESS (process);
8306 CHECK_TYPE (PIPECONN_P (process), Qpipe_process_p, process); 8315 CHECK_TYPE (PIPECONN_P (process), Qpipe_process_p, process);
8316#ifndef MSDOS
8307 int fd = dup (XPROCESS (process)->open_fd[SUBPROCESS_STDOUT]); 8317 int fd = dup (XPROCESS (process)->open_fd[SUBPROCESS_STDOUT]);
8308 if (fd == -1) 8318 if (fd == -1)
8309 report_file_error ("Cannot duplicate file descriptor", Qnil); 8319 report_file_error ("Cannot duplicate file descriptor", Qnil);
8310 return fd; 8320 return fd;
8321#else
8322 /* PIPECONN_P returning true shouldn't be possible on MSDOS. */
8323 emacs_abort ();
8324#endif
8311} 8325}
8312 8326
8313 8327
diff --git a/src/thread.h b/src/thread.h
index cf3ce922c46..b316e916d1d 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -26,6 +26,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
26#endif 26#endif
27 27
28#ifdef MSDOS 28#ifdef MSDOS
29#include <time.h> /* struct rpl_timespec */
29#include <signal.h> /* sigset_t */ 30#include <signal.h> /* sigset_t */
30#endif 31#endif
31 32