Skip to content

Instantly share code, notes, and snippets.

@jwhitmire
Created February 2, 2010 17:06
Show Gist options
  • Save jwhitmire/292823 to your computer and use it in GitHub Desktop.
Save jwhitmire/292823 to your computer and use it in GitHub Desktop.
require 'formula'
class Screen <Formula
url 'http://ftp.gnu.org/gnu/screen/screen-4.0.3.tar.gz'
homepage 'http://www.gnu.org/software/screen/'
md5 '8506fd205028a96c741e4037de6e3c42'
def patches
# Patch stolen from the macports patch: http://trac.macports.org/ticket/20862
DATA
end
def install
system "./configure", "--prefix=#{prefix}", "--disable-debug", "--disable-dependency-tracking"
system "make install"
end
end
__END__
diff --git a/Makefile.in b/Makefile.in
index db683ac..14ba5db 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -79,7 +79,7 @@ install_bin: .version screen
-if [ -f $(DESTDIR)$(bindir)/screen ] && [ ! -f $(DESTDIR)$(bindir)/screen.old ]; then mv $(DESTDIR)$(bindir)/screen $(DESTDIR)$(bindir)/screen.old; fi
rm -f $(DESTDIR)$(bindir)/screen
(cd $(DESTDIR)$(bindir) && ln -sf $(SCREEN) screen)
- cp $(srcdir)/utf8encodings/?? $(DESTDIR)$(SCREENENCODINGS)
+ cp $(srcdir)/utf8encodings/?? $(DSTROOT)$(SCREENENCODINGS)
###############################################################################
install: installdirs install_bin
@@ -95,7 +95,7 @@ install: installdirs install_bin
installdirs:
# Path leading to ETCSCREENRC and Socketdirectory not checked.
- $(srcdir)/etc/mkinstalldirs $(DESTDIR)$(bindir) $(DESTDIR)$(SCREENENCODINGS)
+ $(srcdir)/etc/mkinstalldirs $(DESTDIR)$(bindir) $(DSTROOT)$(SCREENENCODINGS)
cd doc ; $(MAKE) installdirs
uninstall: .version
@@ -122,7 +122,7 @@ tty.c: tty.sh
sh $(srcdir)/tty.sh tty.c
comm.h: comm.c comm.sh config.h
- AWK=$(AWK) CC="$(CC) $(CFLAGS)" srcdir=${srcdir} sh $(srcdir)/comm.sh
+ AWK=$(AWK) srcdir=${srcdir} sh $(srcdir)/comm.sh
osdef.h: osdef.sh config.h osdef.h.in
CPP="$(CPP) $(CPPFLAGS)" srcdir=${srcdir} sh $(srcdir)/osdef.sh
diff --git a/config.h.in b/config.h.in
index 4327855..a32d66b 100644
--- a/config.h.in
+++ b/config.h.in
@@ -208,14 +208,14 @@
* If screen is installed with permissions to update /etc/utmp (such
* as if it is installed set-uid root), define UTMPOK.
*/
-#define UTMPOK
+#undef UTMPOK
/* Set LOGINDEFAULT to one (1)
* if you want entries added to /etc/utmp by default, else set it to
* zero (0).
* LOGINDEFAULT will be one (1) whenever LOGOUTOK is undefined!
*/
-#define LOGINDEFAULT 1
+#undef LOGINDEFAULT
/* Set LOGOUTOK to one (1)
* if you want the user to be able to log her/his windows out.
@@ -231,7 +231,7 @@
* Set CAREFULUTMP to one (1) if you want that users have at least one
* window per screen session logged in.
*/
-#define LOGOUTOK 1
+#undef LOGOUTOK
#undef CAREFULUTMP
diff --git a/configure b/configure
index 75675fc..c9dcbd3 100755
--- a/configure
+++ b/configure
@@ -5572,7 +5572,7 @@ cat >>conftest.$ac_ext <<_ACEOF
#include <time.h> /* to get time_t on SCO */
#include <sys/types.h>
-#if defined(SVR4) && !defined(DGUX)
+#if (defined(SVR4) || defined(__APPLE__)) && !defined(DGUX)
#include <utmpx.h>
#define utmp utmpx
#else
@@ -5581,6 +5581,10 @@ cat >>conftest.$ac_ext <<_ACEOF
#ifdef __hpux
#define pututline _pututline
#endif
+#ifdef __APPLE__
+#define pututline pututxline
+#define getutent getutxent
+#endif
int
main ()
diff --git a/process.c b/process.c
index 7f1a6e1..8e52b02 100644
--- a/process.c
+++ b/process.c
@@ -5466,7 +5466,7 @@ char *data; /* dummy */
*buf = 0;
return;
}
- act.nr = (int)data;
+ act.nr = (int)(intptr_t)data;
act.args = noargs;
act.argl = 0;
DoAction(&act, -1);
diff --git a/pty.c b/pty.c
index f89d44c..38e9709 100644
--- a/pty.c
+++ b/pty.c
@@ -34,7 +34,7 @@
#endif
/* for solaris 2.1, Unixware (SVR4.2) and possibly others */
-#ifdef HAVE_SVR4_PTYS
+#if defined(HAVE_SVR4_PTYS) && !defined(__APPLE__)
# include <sys/stropts.h>
#endif
diff --git a/screen.c b/screen.c
index 70741df..c980514 100644
--- a/screen.c
+++ b/screen.c
@@ -101,6 +101,11 @@
#include "logfile.h" /* islogfile, logfflush */
+#ifdef __APPLE__
+#include <vproc.h>
+#include <vproc_priv.h>
+#endif
+
#ifdef DEBUG
FILE *dfp;
#endif
@@ -929,6 +934,16 @@ char **av;
Panic(0, "No $SCREENDIR with multi screens, please.");
#endif
}
+#ifdef __APPLE__
+ else if (!multi && real_uid == eff_uid) {
+ static char DarwinSockDir[PATH_MAX];
+ if (confstr(_CS_DARWIN_USER_TEMP_DIR, DarwinSockDir, sizeof(DarwinSockDir))) {
+ strlcat(DarwinSockDir, ".screen", sizeof(DarwinSockDir));
+ SockDir = DarwinSockDir;
+ }
+ }
+#endif /* __APPLE__ */
+
#ifdef MULTIUSER
if (multiattach)
{
@@ -1211,6 +1226,11 @@ char **av;
freopen("/dev/null", "w", stderr);
debug("-- screen.back debug started\n");
+#ifdef __APPLE__
+ if (_vprocmgr_detach_from_console(0) != NULL)
+ errx(1, "can't detach from console");
+#endif
+
/*
* This guarantees that the session owner is listed, even when we
* start detached. From now on we should not refer to 'LoginName'
diff --git a/vproc_priv.h b/vproc_priv.h
new file mode 100644
index 0000000..b691c22
--- /dev/null
+++ b/vproc_priv.h
@@ -0,0 +1,128 @@
+#ifndef _VPROC_PRIVATE_H_
+#define _VPROC_PRIVATE_H_
+/*
+ * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_START@
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_END@
+ */
+
+#include <Availability.h>
+#include <sys/types.h>
+#include <sys/cdefs.h>
+#include <sys/syslog.h>
+#include <sys/time.h>
+#include <stdbool.h>
+#include <launch.h>
+#include <vproc.h>
+#include <uuid/uuid.h>
+
+#ifndef VPROC_HAS_TRANSACTIONS
+ #define VPROC_HAS_TRANSACTIONS
+#endif
+
+__BEGIN_DECLS
+
+#pragma GCC visibility push(default)
+
+/* DO NOT use this. This is a hack for 'launchctl' */
+#define VPROC_MAGIC_UNLOAD_SIGNAL 0x4141504C
+/* DO NOT use this. This is a hack for 'loginwindow' */
+#define VPROC_MAGIC_TRYKILL_SIGNAL 0x6161706C
+
+typedef enum {
+ VPROC_GSK_LAST_EXIT_STATUS = 1,
+ VPROC_GSK_GLOBAL_ON_DEMAND,
+ VPROC_GSK_MGR_UID,
+ VPROC_GSK_MGR_PID,
+ VPROC_GSK_IS_MANAGED,
+ VPROC_GSK_MGR_NAME,
+ VPROC_GSK_BASIC_KEEPALIVE,
+ VPROC_GSK_START_INTERVAL,
+ VPROC_GSK_IDLE_TIMEOUT,
+ VPROC_GSK_EXIT_TIMEOUT,
+ VPROC_GSK_ENVIRONMENT,
+ VPROC_GSK_ALLJOBS,
+ VPROC_GSK_GLOBAL_LOG_MASK,
+ VPROC_GSK_GLOBAL_UMASK,
+ VPROC_GSK_ABANDON_PROCESS_GROUP,
+ VPROC_GSK_TRANSACTIONS_ENABLED,
+ VPROC_GSK_WEIRD_BOOTSTRAP,
+ VPROC_GSK_WAITFORDEBUGGER,
+ VPROC_GSK_SECURITYSESSION,
+ VPROC_GSK_SHUTDOWN_DEBUGGING,
+ VPROC_GSK_VERBOSE_BOOT,
+ VPROC_GSK_PERUSER_SUSPEND,
+ VPROC_GSK_PERUSER_RESUME,
+ VPROC_GSK_JOB_OVERRIDES_DB,
+ VPROC_GSK_JOB_CACHE_DB,
+ VPROC_GSK_EMBEDDEDROOTEQUIVALENT,
+} vproc_gsk_t;
+
+typedef unsigned int vproc_flags_t;
+/* For _vproc_kickstart_by_label() -- instructs launchd to kickstart the job to stall before exec(2). */
+#define VPROCFLAG_STALL_JOB_EXEC 1 << 1
+
+vproc_t vprocmgr_lookup_vproc(const char *label);
+vproc_t vproc_retain(vproc_t vp);
+void vproc_release(vproc_t vp);
+
+vproc_err_t vproc_swap_integer(vproc_t vp, vproc_gsk_t key, int64_t *inval, int64_t *outval);
+vproc_err_t vproc_swap_complex(vproc_t vp, vproc_gsk_t key, launch_data_t inval, launch_data_t *outval);
+vproc_err_t vproc_swap_string(vproc_t vp, vproc_gsk_t key, const char *instr, char **outstr);
+
+vproc_err_t _vproc_get_last_exit_status(int *wstatus);
+vproc_err_t _vproc_set_global_on_demand(bool val);
+
+typedef void (*_vprocmgr_log_drain_callback_t)(struct timeval *when, pid_t from_pid, pid_t about_pid, uid_t sender_uid, gid_t sender_gid, int priority, const char *from_name, const char *about_name, const char *session_name, const char *msg);
+
+vproc_err_t _vprocmgr_log_drain(vproc_t vp, pthread_mutex_t *optional_mutex_around_callback, _vprocmgr_log_drain_callback_t func);
+
+vproc_err_t _vproc_send_signal_by_label(const char *label, int sig);
+vproc_err_t _vproc_kickstart_by_label(const char *label, pid_t *out_pid, mach_port_t *out_port_name, mach_port_t *out_obsrvr_port, vproc_flags_t flags);
+vproc_err_t _vproc_wait_by_label(const char *label, int *out_wstatus);
+
+void _vproc_log(int pri, const char *msg, ...) __attribute__((format(printf, 2, 3)));
+void _vproc_log_error(int pri, const char *msg, ...) __attribute__((format(printf, 2, 3)));
+void _vproc_logv(int pri, int err, const char *msg, va_list ap) __attribute__((format(printf, 3, 0)));
+
+#define VPROCMGR_SESSION_LOGINWINDOW "LoginWindow"
+#define VPROCMGR_SESSION_BACKGROUND "Background"
+#define VPROCMGR_SESSION_AQUA "Aqua"
+#define VPROCMGR_SESSION_STANDARDIO "StandardIO"
+#define VPROCMGR_SESSION_SYSTEM "System"
+
+vproc_err_t _vprocmgr_move_subset_to_user(uid_t target_user, const char *session_type, uint64_t flags);
+vproc_err_t _vprocmgr_switch_to_session(const char *target_session, vproc_flags_t flags);
+vproc_err_t _vprocmgr_detach_from_console(vproc_flags_t flags);
+
+void _vproc_standby_begin(void) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_NA);
+void _vproc_standby_end(void) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_NA);
+size_t _vproc_standby_count(void) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_NA);
+size_t _vproc_standby_timeout(void) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_NA);
+
+kern_return_t _vproc_transaction_count_for_pid(pid_t p, int32_t *count, bool *condemned) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_NA);
+bool _vproc_pid_is_managed(pid_t p) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_NA);
+void _vproc_transaction_try_exit(int status) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_NA);
+void _vproc_transaction_begin(void) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_NA);
+void _vproc_transaction_end(void) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_NA);
+size_t _vproc_transaction_count(void) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_NA);
+
+#pragma GCC visibility pop
+
+__END_DECLS
+
+#endif
diff --git a/window.c b/window.c
index 3b60ae0..5cae839 100644
--- a/window.c
+++ b/window.c
@@ -25,6 +25,7 @@
#include <sys/stat.h>
#include <signal.h>
#include <fcntl.h>
+#include <unistd.h>
#ifndef sun
# include <sys/ioctl.h>
#endif
@@ -1387,6 +1388,38 @@ char **args, *ttyn;
return pid;
}
+#ifdef RUN_LOGIN
+/*
+ * All of the logic to maintain utmpx is now built into /usr/bin/login, so
+ * all we need to do is call it, and pass the shell command to it.
+ */
+extern char *LoginName;
+
+static int
+run_login(const char *path, char *const argv[], char *const envp[])
+{
+ const char *shargs[MAXARGS + 1 + 3];
+ const char **fp, **tp;
+
+ if (access(path, X_OK) < 0)
+ return -1;
+ shargs[0] = "login";
+ shargs[1] = (*argv[0] == '-') ? "-pfq" : "-pflq";
+ shargs[2] = LoginName;
+ shargs[3] = path;
+ fp = (const char **)argv + 1;
+ tp = shargs + 4;
+ /* argv has already been check for length */
+ while ((*tp++ = *fp++) != NULL) {}
+ /* shouldn't return unless there was an error */
+ return (execve("/usr/bin/login", (char *const*)shargs, envp));
+}
+
+/* replace the following occurrences of execve() with run_login() */
+#define execve run_login
+
+#endif /* RUN_LOGIN */
+
void
execvpe(prog, args, env)
char *prog, **args, **env;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment