1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: init.c |
2 | * File: init.c |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * $Id: init.C,v 1.20 2004/01/31 00:20:21 pcg Exp $ |
|
|
5 | * |
4 | * |
6 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
7 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
6 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
8 | * - original version |
7 | * - original version |
9 | * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> |
8 | * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> |
… | |
… | |
327 | #endif |
326 | #endif |
328 | #ifdef KEEP_SCROLLCOLOR |
327 | #ifdef KEEP_SCROLLCOLOR |
329 | COLOR_SCROLLBAR, |
328 | COLOR_SCROLLBAR, |
330 | COLOR_SCROLLTROUGH, |
329 | COLOR_SCROLLTROUGH, |
331 | #endif /* KEEP_SCROLLCOLOR */ |
330 | #endif /* KEEP_SCROLLCOLOR */ |
|
|
331 | |
332 | }; |
332 | }; |
333 | |
333 | |
334 | const char *const xa_names[NUM_XA] = |
334 | const char *const xa_names[NUM_XA] = |
335 | { |
335 | { |
336 | "TEXT", |
336 | "TEXT", |
… | |
… | |
445 | ttymode = S_IRUSR | S_IWUSR | S_IWGRP; |
445 | ttymode = S_IRUSR | S_IWUSR | S_IWGRP; |
446 | ttygid = gr->gr_gid; |
446 | ttygid = gr->gr_gid; |
447 | } |
447 | } |
448 | else |
448 | else |
449 | #endif /* TTY_GID_SUPPORT */ |
449 | #endif /* TTY_GID_SUPPORT */ |
|
|
450 | |
450 | { |
451 | { |
451 | ttymode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH; |
452 | ttymode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH; |
452 | ttygid = getgid (); |
453 | ttygid = getgid (); |
453 | } |
454 | } |
454 | |
455 | |
… | |
… | |
658 | #ifndef NO_OLD_SELECTION |
659 | #ifndef NO_OLD_SELECTION |
659 | |
660 | |
660 | else if (STRNCASECMP(rs[Rs_selectstyle], "old", 3) == 0) |
661 | else if (STRNCASECMP(rs[Rs_selectstyle], "old", 3) == 0) |
661 | selection_style = OLD_SELECT; |
662 | selection_style = OLD_SELECT; |
662 | #endif |
663 | #endif |
|
|
664 | |
663 | } |
665 | } |
664 | |
666 | |
665 | #ifdef HAVE_SCROLLBARS |
667 | #ifdef HAVE_SCROLLBARS |
666 | setup_scrollbar (rs[Rs_scrollBar_align], rs[Rs_scrollstyle], |
668 | setup_scrollbar (rs[Rs_scrollBar_align], rs[Rs_scrollstyle], |
667 | rs[Rs_scrollBar_thickness]); |
669 | rs[Rs_scrollBar_thickness]); |
668 | #endif |
670 | #endif |
669 | |
671 | |
670 | TermWin.fontset = new rxvt_fontset (this); |
672 | TermWin.fontset = new rxvt_fontset (this); |
671 | TermWin.fontset->populate (rs[Rs_font]); |
673 | TermWin.fontset->populate (rs[Rs_font]); |
672 | TermWin.fwidth = TermWin.fontset->base_font ()->width; |
674 | TermWin.fwidth = TermWin.fontset->base_font ()->width; |
… | |
… | |
806 | #endif |
808 | #endif |
807 | #if HAVE_NL_LANGINFO |
809 | #if HAVE_NL_LANGINFO |
808 | free (codeset); |
810 | free (codeset); |
809 | codeset = strdup (nl_langinfo (CODESET)); |
811 | codeset = strdup (nl_langinfo (CODESET)); |
810 | enc_utf8 = !STRCASECMP (codeset, "UTF-8") |
812 | enc_utf8 = !STRCASECMP (codeset, "UTF-8") |
811 | || !STRCASECMP (codeset, "UTF8"); |
813 | || !STRCASECMP (codeset, "UTF8"); |
812 | #else |
814 | #else |
813 | enc_utf8 = 1; |
815 | enc_utf8 = 1; |
814 | #endif |
816 | #endif |
815 | } |
817 | } |
816 | |
818 | |
… | |
… | |
946 | |
948 | |
947 | if (!rXParseAllocColor (&xcol, rs[Rs_color + i])) |
949 | if (!rXParseAllocColor (&xcol, rs[Rs_color + i])) |
948 | { |
950 | { |
949 | switch (i) |
951 | switch (i) |
950 | { |
952 | { |
951 | case Color_fg: |
953 | case Color_fg: |
952 | case Color_bg: |
954 | case Color_bg: |
953 | /* fatal: need bg/fg color */ |
955 | /* fatal: need bg/fg color */ |
954 | rxvt_print_error ("aborting"); |
956 | rxvt_print_error ("aborting"); |
955 | exit (EXIT_FAILURE); |
957 | exit (EXIT_FAILURE); |
956 | /* NOTREACHED */ |
958 | /* NOTREACHED */ |
957 | break; |
959 | break; |
958 | #ifndef NO_CURSORCOLOR |
960 | #ifndef NO_CURSORCOLOR |
959 | case Color_cursor2: |
961 | case Color_cursor2: |
960 | xcol = PixColors[Color_fg]; |
962 | xcol = PixColors[Color_fg]; |
961 | break; |
963 | break; |
962 | #endif /* ! NO_CURSORCOLOR */ |
964 | #endif /* ! NO_CURSORCOLOR */ |
963 | case Color_pointer: |
965 | case Color_pointer: |
964 | xcol = PixColors[Color_fg]; |
966 | xcol = PixColors[Color_fg]; |
965 | break; |
967 | break; |
966 | default: |
968 | default: |
967 | xcol = PixColors[Color_bg]; /* None */ |
969 | xcol = PixColors[Color_bg]; /* None */ |
968 | break; |
970 | break; |
969 | } |
971 | } |
970 | } |
972 | } |
971 | } |
973 | } |
972 | |
974 | |
973 | PixColors[i] = xcol; |
975 | PixColors[i] = xcol; |
… | |
… | |
1000 | * xcol[1] == top shadow |
1002 | * xcol[1] == top shadow |
1001 | * xcol[2] == bot shadow */ |
1003 | * xcol[2] == bot shadow */ |
1002 | |
1004 | |
1003 | xcol[1] = PixColors[Color_scroll]; |
1005 | xcol[1] = PixColors[Color_scroll]; |
1004 | # ifdef PREFER_24BIT |
1006 | # ifdef PREFER_24BIT |
1005 | xcol[0].set (R, 65535, 65535, 65535); |
1007 | xcol[0].set (this, 65535, 65535, 65535); |
1006 | /* XFreeColors(Xdisplay, XCMAP, &(xcol[0].pixel), 1, ~0); */ |
1008 | /* XFreeColors(Xdisplay, XCMAP, &(xcol[0].pixel), 1, ~0); */ |
1007 | # else |
1009 | # else |
1008 | xcol[0].set (WhitePixel(Xdisplay, Xscreen)); |
1010 | xcol[0].set (this, WhitePixel (Xdisplay, Xscreen)); |
1009 | # endif |
1011 | # endif |
1010 | |
1012 | |
1011 | unsigned short pr1, pg1, pb1, pr0, pg0, pb0; |
1013 | unsigned short pr1, pg1, pb1, pr0, pg0, pb0; |
1012 | |
1014 | |
1013 | xcol[0].get (R, pr0, pg0, pb0); |
1015 | xcol[0].get (this, pr0, pg0, pb0); |
1014 | xcol[1].get (R, pr1, pg1, pb1); |
1016 | xcol[1].get (this, pr1, pg1, pb1); |
1015 | |
1017 | |
1016 | /* bottomShadowColor */ |
1018 | /* bottomShadowColor */ |
1017 | if (!xcol[2].set (pr1 / 2, pg1 / 2, pb1 / 2)) |
1019 | if (!xcol[2].set (this, pr1 / 2, pg1 / 2, pb1 / 2)) |
1018 | xcol[2] = PixColors[Color_Black]; |
1020 | xcol[2] = PixColors[Color_Black]; |
1019 | |
1021 | |
1020 | PixColors[Color_bottomShadow] = xcol[2]; |
1022 | PixColors[Color_bottomShadow] = xcol[2]; |
1021 | |
1023 | |
1022 | /* topShadowColor */ |
1024 | /* topShadowColor */ |
|
|
1025 | if (!xcol[1].set (this, |
1023 | if (!xcol[1].set ( min (pr0, max (pr0 / 5, pr1) * 7 / 5), |
1026 | min (pr0, max (pr0 / 5, pr1) * 7 / 5), |
1024 | min (pg0, max (pg0 / 5, pg1) * 7 / 5), |
1027 | min (pg0, max (pg0 / 5, pg1) * 7 / 5), |
1025 | min (pb0, max (pb0 / 5, pb1) * 7 / 5))) |
1028 | min (pb0, max (pb0 / 5, pb1) * 7 / 5))) |
1026 | xcol[1] = PixColors[Color_White]; |
1029 | xcol[1] = PixColors[Color_White]; |
1027 | |
1030 | |
1028 | PixColors[Color_topShadow] = xcol[1]; |
1031 | PixColors[Color_topShadow] = xcol[1]; |
… | |
… | |
1044 | i -= 8; |
1047 | i -= 8; |
1045 | #ifndef NO_BRIGHTCOLOR |
1048 | #ifndef NO_BRIGHTCOLOR |
1046 | rs[Rs_color + idx] = rs[Rs_color + minBrightCOLOR + i]; |
1049 | rs[Rs_color + idx] = rs[Rs_color + minBrightCOLOR + i]; |
1047 | return; |
1050 | return; |
1048 | #endif |
1051 | #endif |
|
|
1052 | |
1049 | } |
1053 | } |
1050 | |
1054 | |
1051 | if (i >= 0 && i <= 7) /* normal colors */ |
1055 | if (i >= 0 && i <= 7) /* normal colors */ |
1052 | rs[Rs_color + idx] = rs[Rs_color + minCOLOR + i]; |
1056 | rs[Rs_color + idx] = rs[Rs_color + minCOLOR + i]; |
1053 | } |
1057 | } |
… | |
… | |
1086 | { |
1090 | { |
1087 | if (kc[k] == 0) |
1091 | if (kc[k] == 0) |
1088 | break; |
1092 | break; |
1089 | switch (XKeycodeToKeysym(Xdisplay, kc[k], 0)) |
1093 | switch (XKeycodeToKeysym(Xdisplay, kc[k], 0)) |
1090 | { |
1094 | { |
1091 | case XK_Num_Lock: |
1095 | case XK_Num_Lock: |
1092 | ModNumLockMask = modmasks[i - 1]; |
1096 | ModNumLockMask = modmasks[i - 1]; |
1093 | /* FALLTHROUGH */ |
1097 | /* FALLTHROUGH */ |
1094 | default: |
1098 | default: |
1095 | continue; /* for(;;) */ |
1099 | continue; /* for(;;) */ |
1096 | case XK_Meta_L: |
1100 | case XK_Meta_L: |
1097 | case XK_Meta_R: |
1101 | case XK_Meta_R: |
1098 | cm = "meta"; |
1102 | cm = "meta"; |
1099 | realmeta = i; |
1103 | realmeta = i; |
1100 | break; |
1104 | break; |
1101 | case XK_Alt_L: |
1105 | case XK_Alt_L: |
1102 | case XK_Alt_R: |
1106 | case XK_Alt_R: |
1103 | cm = "alt"; |
1107 | cm = "alt"; |
1104 | realalt = i; |
1108 | realalt = i; |
1105 | break; |
1109 | break; |
1106 | case XK_Super_L: |
1110 | case XK_Super_L: |
1107 | case XK_Super_R: |
1111 | case XK_Super_R: |
1108 | cm = "super"; |
1112 | cm = "super"; |
1109 | break; |
1113 | break; |
1110 | case XK_Hyper_L: |
1114 | case XK_Hyper_L: |
1111 | case XK_Hyper_R: |
1115 | case XK_Hyper_R: |
1112 | cm = "hyper"; |
1116 | cm = "hyper"; |
1113 | break; |
1117 | break; |
1114 | } |
1118 | } |
1115 | if (rsmod && STRNCASECMP(rsmod, cm, STRLEN(cm)) == 0) |
1119 | if (rsmod && STRNCASECMP(rsmod, cm, STRLEN(cm)) == 0) |
1116 | requestedmeta = i; |
1120 | requestedmeta = i; |
1117 | } |
1121 | } |
1118 | } |
1122 | } |
… | |
… | |
1164 | RootWindow(Xdisplay, Xscreen), |
1168 | RootWindow(Xdisplay, Xscreen), |
1165 | Xvisual, AllocNone); |
1169 | Xvisual, AllocNone); |
1166 | } |
1170 | } |
1167 | } |
1171 | } |
1168 | #endif |
1172 | #endif |
|
|
1173 | |
1169 | } |
1174 | } |
1170 | |
1175 | |
1171 | /* grab colors before netscape does */ |
1176 | /* grab colors before netscape does */ |
1172 | Get_Colours (); |
1177 | Get_Colours (); |
1173 | |
1178 | |
… | |
… | |
1185 | |
1190 | |
1186 | attributes.background_pixel = PixColors[Color_fg]; |
1191 | attributes.background_pixel = PixColors[Color_fg]; |
1187 | attributes.border_pixel = PixColors[Color_border]; |
1192 | attributes.border_pixel = PixColors[Color_border]; |
1188 | attributes.colormap = Xcmap; |
1193 | attributes.colormap = Xcmap; |
1189 | TermWin.parent[0] = XCreateWindow (Xdisplay, DefaultRootWindow (Xdisplay), |
1194 | TermWin.parent[0] = XCreateWindow (Xdisplay, DefaultRootWindow (Xdisplay), |
1190 | szHint.x, szHint.y, |
1195 | szHint.x, szHint.y, |
1191 | szHint.width, szHint.height, |
1196 | szHint.width, szHint.height, |
1192 | TermWin.ext_bwidth, |
1197 | TermWin.ext_bwidth, |
1193 | Xdepth, InputOutput, |
1198 | Xdepth, InputOutput, |
1194 | Xvisual, |
1199 | Xvisual, |
1195 | CWBackPixel | CWBorderPixel |
1200 | CWBackPixel | CWBorderPixel |
1196 | | CWColormap, &attributes); |
1201 | | CWColormap, &attributes); |
1197 | #else |
1202 | #else |
1198 | TermWin.parent[0] = XCreateSimpleWindow (Xdisplay, DefaultRootWindow (Xdisplay), |
1203 | TermWin.parent[0] = XCreateSimpleWindow (Xdisplay, DefaultRootWindow (Xdisplay), |
1199 | szHint.x, szHint.y, |
1204 | szHint.x, szHint.y, |
1200 | szHint.width, |
1205 | szHint.width, |
1201 | szHint.height, |
1206 | szHint.height, |
1202 | TermWin.ext_bwidth, |
1207 | TermWin.ext_bwidth, |
1203 | PixColors[Color_border], |
1208 | PixColors[Color_border], |
1204 | PixColors[Color_fg]); |
1209 | PixColors[Color_fg]); |
1205 | #endif |
1210 | #endif |
1206 | |
1211 | |
1207 | xterm_seq (XTerm_title, rs[Rs_title], CHAR_ST); |
1212 | xterm_seq (XTerm_title, rs[Rs_title], CHAR_ST); |
1208 | xterm_seq (XTerm_iconName, rs[Rs_iconName], CHAR_ST); |
1213 | xterm_seq (XTerm_iconName, rs[Rs_iconName], CHAR_ST); |
1209 | |
1214 | |
… | |
… | |
1241 | blackcolour.red = 0; |
1246 | blackcolour.red = 0; |
1242 | blackcolour.green = 0; |
1247 | blackcolour.green = 0; |
1243 | blackcolour.blue = 0; |
1248 | blackcolour.blue = 0; |
1244 | Font f = XLoadFont (Xdisplay, "fixed"); |
1249 | Font f = XLoadFont (Xdisplay, "fixed"); |
1245 | blank_cursor = XCreateGlyphCursor (Xdisplay, f, f, ' ', ' ', |
1250 | blank_cursor = XCreateGlyphCursor (Xdisplay, f, f, ' ', ' ', |
1246 | &blackcolour, &blackcolour); |
1251 | &blackcolour, &blackcolour); |
1247 | XUnloadFont (Xdisplay, f); |
1252 | XUnloadFont (Xdisplay, f); |
1248 | } |
1253 | } |
1249 | #endif |
1254 | #endif |
1250 | |
1255 | |
1251 | /* the vt window */ |
1256 | /* the vt window */ |
1252 | TermWin.vt = XCreateSimpleWindow(Xdisplay, TermWin.parent[0], |
1257 | TermWin.vt = XCreateSimpleWindow(Xdisplay, TermWin.parent[0], |
1253 | window_vt_x, window_vt_y, |
1258 | window_vt_x, window_vt_y, |
1254 | TermWin_TotalWidth(), |
1259 | TermWin_TotalWidth(), |
1255 | TermWin_TotalHeight(), |
1260 | TermWin_TotalHeight(), |
1256 | 0, |
1261 | 0, |
1257 | PixColors[Color_fg], |
1262 | PixColors[Color_fg], |
1258 | PixColors[Color_bg]); |
1263 | PixColors[Color_bg]); |
1259 | #ifdef DEBUG_X |
1264 | #ifdef DEBUG_X |
1260 | XStoreName(Xdisplay, TermWin.vt, "vt window"); |
1265 | XStoreName(Xdisplay, TermWin.vt, "vt window"); |
1261 | #endif |
1266 | #endif |
1262 | |
1267 | |
1263 | vt_emask = (ExposureMask | ButtonPressMask | ButtonReleaseMask |
1268 | vt_emask = (ExposureMask | ButtonPressMask | ButtonReleaseMask |
… | |
… | |
1277 | #if defined(MENUBAR) && (MENUBAR_MAX > 1) |
1282 | #if defined(MENUBAR) && (MENUBAR_MAX > 1) |
1278 | |
1283 | |
1279 | if (menuBar_height()) |
1284 | if (menuBar_height()) |
1280 | { |
1285 | { |
1281 | menuBar.win = XCreateSimpleWindow(Xdisplay, TermWin.parent[0], |
1286 | menuBar.win = XCreateSimpleWindow(Xdisplay, TermWin.parent[0], |
1282 | window_vt_x, 0, |
1287 | window_vt_x, 0, |
1283 | TermWin_TotalWidth(), |
1288 | TermWin_TotalWidth(), |
1284 | menuBar_TotalHeight(), |
1289 | menuBar_TotalHeight(), |
1285 | 0, |
1290 | 0, |
1286 | PixColors[Color_fg], |
1291 | PixColors[Color_fg], |
1287 | PixColors[Color_scroll]); |
1292 | PixColors[Color_scroll]); |
1288 | #ifdef DEBUG_X |
1293 | #ifdef DEBUG_X |
1289 | |
1294 | |
1290 | XStoreName(Xdisplay, menuBar.win, "menubar"); |
1295 | XStoreName(Xdisplay, menuBar.win, "menubar"); |
1291 | #endif |
1296 | #endif |
1292 | |
1297 | |
… | |
… | |
1315 | /* graphics context for the vt window */ |
1320 | /* graphics context for the vt window */ |
1316 | gcvalue.foreground = PixColors[Color_fg]; |
1321 | gcvalue.foreground = PixColors[Color_fg]; |
1317 | gcvalue.background = PixColors[Color_bg]; |
1322 | gcvalue.background = PixColors[Color_bg]; |
1318 | gcvalue.graphics_exposures = 1; |
1323 | gcvalue.graphics_exposures = 1; |
1319 | TermWin.gc = XCreateGC(Xdisplay, TermWin.vt, |
1324 | TermWin.gc = XCreateGC(Xdisplay, TermWin.vt, |
1320 | GCForeground | GCBackground |
1325 | GCForeground | GCBackground |
1321 | | GCGraphicsExposures, &gcvalue); |
1326 | | GCGraphicsExposures, &gcvalue); |
1322 | |
1327 | |
1323 | #if defined(MENUBAR) || defined(RXVT_SCROLLBAR) |
1328 | #if defined(MENUBAR) || defined(RXVT_SCROLLBAR) |
1324 | |
1329 | |
1325 | gcvalue.foreground = PixColors[Color_topShadow]; |
1330 | gcvalue.foreground = PixColors[Color_topShadow]; |
1326 | topShadowGC = XCreateGC(Xdisplay, TermWin.vt, |
1331 | topShadowGC = XCreateGC(Xdisplay, TermWin.vt, |
1327 | GCForeground, &gcvalue); |
1332 | GCForeground, &gcvalue); |
1328 | gcvalue.foreground = PixColors[Color_bottomShadow]; |
1333 | gcvalue.foreground = PixColors[Color_bottomShadow]; |
1329 | botShadowGC = XCreateGC(Xdisplay, TermWin.vt, |
1334 | botShadowGC = XCreateGC(Xdisplay, TermWin.vt, |
1330 | GCForeground, &gcvalue); |
1335 | GCForeground, &gcvalue); |
1331 | gcvalue.foreground = PixColors[(XDEPTH <= 2 ? Color_fg |
1336 | gcvalue.foreground = PixColors[(XDEPTH <= 2 ? Color_fg |
1332 | : Color_scroll)]; |
1337 | : Color_scroll)]; |
1333 | scrollbarGC = XCreateGC(Xdisplay, TermWin.vt, |
1338 | scrollbarGC = XCreateGC(Xdisplay, TermWin.vt, |
1334 | GCForeground, &gcvalue); |
1339 | GCForeground, &gcvalue); |
1335 | #endif |
1340 | #endif |
1336 | } |
1341 | } |
1337 | |
1342 | |
1338 | /*----------------------------------------------------------------------*/ |
1343 | /*----------------------------------------------------------------------*/ |
1339 | /* |
1344 | /* |
… | |
… | |
1392 | |
1397 | |
1393 | #ifndef __QNX__ |
1398 | #ifndef __QNX__ |
1394 | /* spin off the command interpreter */ |
1399 | /* spin off the command interpreter */ |
1395 | switch (cmd_pid = fork ()) |
1400 | switch (cmd_pid = fork ()) |
1396 | { |
1401 | { |
1397 | case -1: |
1402 | case -1: |
1398 | rxvt_print_error("can't fork"); |
1403 | rxvt_print_error("can't fork"); |
1399 | return -1; |
1404 | return -1; |
1400 | case 0: |
1405 | case 0: |
1401 | close (cfd); /* only keep tty_fd and STDERR open */ |
1406 | close (cfd); /* only keep tty_fd and STDERR open */ |
1402 | close (Xfd); |
1407 | close (Xfd); |
1403 | if (rxvt_control_tty (tty_fd, ttydev) < 0) |
1408 | if (rxvt_control_tty (tty_fd, ttydev) < 0) |
1404 | rxvt_print_error ("could not obtain control of tty"); |
1409 | rxvt_print_error ("could not obtain control of tty"); |
1405 | else |
1410 | else |
|
|
1411 | { |
|
|
1412 | /* Reopen stdin, stdout and stderr over the tty file descriptor */ |
|
|
1413 | dup2 (tty_fd, STDIN_FILENO); |
|
|
1414 | dup2 (tty_fd, STDOUT_FILENO); |
|
|
1415 | dup2 (tty_fd, STDERR_FILENO); |
|
|
1416 | |
|
|
1417 | if (tty_fd > 2) |
|
|
1418 | close (tty_fd); |
|
|
1419 | |
|
|
1420 | run_child (argv); |
|
|
1421 | } |
|
|
1422 | exit (EXIT_FAILURE); |
|
|
1423 | /* NOTREACHED */ |
|
|
1424 | default: |
1406 | { |
1425 | { |
1407 | /* Reopen stdin, stdout and stderr over the tty file descriptor */ |
1426 | #if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT) |
|
|
1427 | int fdstdin; |
|
|
1428 | |
|
|
1429 | fdstdin = dup (STDIN_FILENO); |
1408 | dup2 (tty_fd, STDIN_FILENO); |
1430 | dup2 (tty_fd, STDIN_FILENO); |
|
|
1431 | #endif |
|
|
1432 | |
|
|
1433 | #ifdef UTMP_SUPPORT |
|
|
1434 | privileged_utmp (SAVE); |
|
|
1435 | #endif |
|
|
1436 | |
|
|
1437 | #if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT) |
|
|
1438 | |
1409 | dup2 (tty_fd, STDOUT_FILENO); |
1439 | dup2 (fdstdin, STDIN_FILENO); |
1410 | dup2 (tty_fd, STDERR_FILENO); |
|
|
1411 | |
|
|
1412 | if (tty_fd > 2) |
|
|
1413 | close (tty_fd); |
1440 | close (fdstdin); |
|
|
1441 | #endif |
1414 | |
1442 | |
1415 | run_child (argv); |
|
|
1416 | } |
1443 | } |
1417 | exit (EXIT_FAILURE); |
|
|
1418 | /* NOTREACHED */ |
|
|
1419 | default: |
|
|
1420 | { |
|
|
1421 | #if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT) |
|
|
1422 | int fdstdin; |
|
|
1423 | |
|
|
1424 | fdstdin = dup (STDIN_FILENO); |
|
|
1425 | dup2 (tty_fd, STDIN_FILENO); |
|
|
1426 | #endif |
|
|
1427 | |
|
|
1428 | #ifdef UTMP_SUPPORT |
|
|
1429 | privileged_utmp (SAVE); |
|
|
1430 | #endif |
|
|
1431 | |
|
|
1432 | #if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT) |
|
|
1433 | |
|
|
1434 | dup2 (fdstdin, STDIN_FILENO); |
|
|
1435 | close (fdstdin); |
|
|
1436 | #endif |
|
|
1437 | |
|
|
1438 | } |
|
|
1439 | close (tty_fd); /* keep STDERR_FILENO, cmd_fd, Xfd open */ |
1444 | close (tty_fd); /* keep STDERR_FILENO, cmd_fd, Xfd open */ |
1440 | break; |
1445 | break; |
1441 | } |
1446 | } |
1442 | #else /* __QNX__ uses qnxspawn() */ |
1447 | #else /* __QNX__ uses qnxspawn() */ |
1443 | fchmod (tty_fd, 0622); |
1448 | fchmod (tty_fd, 0622); |
1444 | fcntl (tty_fd, F_SETFD, FD_CLOEXEC); |
1449 | fcntl (tty_fd, F_SETFD, FD_CLOEXEC); |
1445 | fcntl (cfd, F_SETFD, FD_CLOEXEC); |
1450 | fcntl (cfd, F_SETFD, FD_CLOEXEC); |
… | |
… | |
1479 | { |
1484 | { |
1480 | if (ioctl (fd, SRIOCSREDIR, NULL) < 0) |
1485 | if (ioctl (fd, SRIOCSREDIR, NULL) < 0) |
1481 | close (fd); |
1486 | close (fd); |
1482 | } |
1487 | } |
1483 | #endif /* SRIOCSREDIR */ |
1488 | #endif /* SRIOCSREDIR */ |
|
|
1489 | |
1484 | } |
1490 | } |
1485 | |
1491 | |
1486 | /* reset signals and spin off the command interpreter */ |
1492 | /* reset signals and spin off the command interpreter */ |
1487 | signal (SIGINT, SIG_DFL); |
1493 | signal (SIGINT, SIG_DFL); |
1488 | signal (SIGQUIT, SIG_DFL); |
1494 | signal (SIGQUIT, SIG_DFL); |
… | |
… | |
1583 | } |
1589 | } |
1584 | arg_v = arg_a; |
1590 | arg_v = arg_a; |
1585 | } |
1591 | } |
1586 | iov_a[0] = iov_a[1] = iov_a[2] = tty_fd; |
1592 | iov_a[0] = iov_a[1] = iov_a[2] = tty_fd; |
1587 | cmd_pid = qnx_spawn(0, 0, 0, -1, -1, |
1593 | cmd_pid = qnx_spawn(0, 0, 0, -1, -1, |
1588 | _SPAWN_SETSID | _SPAWN_TCSETPGRP, |
1594 | _SPAWN_SETSID | _SPAWN_TCSETPGRP, |
1589 | command, arg_v, environ, iov_a, 0); |
1595 | command, arg_v, environ, iov_a, 0); |
1590 | if (login) |
1596 | if (login) |
1591 | free(login); |
1597 | free(login); |
1592 | |
1598 | |
1593 | close(tty_fd); |
1599 | close(tty_fd); |
1594 | return cmd_fd; |
1600 | return cmd_fd; |