⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lockscreen.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
#ifndef lint#ifdef sccsstatic  char sccsid[] = "@(#)lockscreen.c 1.1 92/07/30 SMI";#endif#endif/* * Sun Microsystems, Inc. *//* * 	Overview:	Lock Screen: Lockscreen waits for the user that created *			it (or the root if the -r switch is given) to login. *			Until then, the window described *			by WINDOW_PARENT in the environment is covered *			and a sun logo is displayed on the screen at random *			places. Anyone can logout from the suntools environment *			on which lockscreen is running if the "-e" switch *			was given when lockscreen was started.  Along with *			security, running this program when the machine is not *			being used helps limit phorphorus burn of the screen *			(not significant for sun 2 bw). */#include <suntool/tool_hs.h>#include <pwd.h>#include <stdio.h>#include <ctype.h>#include <vfork.h>#include <errno.h>#include <sys/file.h>#include <sys/resource.h>#include <sys/stat.h>#include <sys/wait.h>#include <sunwindow/cms.h>#include <sunwindow/defaults.h>#include <sunwindow/win_ioctl.h>#include <suntool/alert.h>#include <suntool/frame.h>#include <suntool/panel.h>#define FIVEMIN 300;static char *fg_default = "lockscreen_default";static char *bg_default = "/usr/local/computeserver";static int timeout = FIVEMIN;static void sigwinchcatcher();static make_twinkle();static void abort_proc();static char *getpath(), *expandname();static char fg_prog[255];static char bg_prog[255];static char *dummy_argv[2], **fg_argv;static int fg_pid = 0, bg_pid = 0;static int fork_var = 1;static int countdown;static short first_char;#define CMSIZE 32		/* must be power of two */static char cmsname[CMS_NAMESIZE];static u_char	red[CMSIZE];static u_char	green[CMSIZE];static u_char	blue[CMSIZE];static	struct tool *tool;static	struct toolsw  *panel_toolsw;static	struct rect rectcreate;static	int parentfd = 0;static	int clear_screen = 0;static	char *tool_label = "Lockscreen 2.0";static	char *progname;static	int exitenable = 0;static	int rootenable = 0;static	int no_lock = 0;static	int show_hostname = 0;static	struct timeval tooltimer = {1, 0};static	struct timeval sectimer  = {1, 0};static	struct rect imagerect = {0, 0, 64, 64};static  colormonitor;		/* true if running on color monitor */#define BIG_FONT   "/usr/lib/fonts/fixedwidthfonts/gallant.r.19"#define SMALL_FONT "/usr/lib/fonts/fixedwidthfonts/screen.b.12"static struct pixfont *big_font, *small_font;static	Panel_item  hostname_item, name_item, passwd_item, abort_item,                   instructions_item, msg_item, exit_item;static	short icon_data[256] = {#include <images/lockscreen.icon>};mpr_static(lkscr_icpr, 64, 64, 1, icon_data);static	struct pixrect *lockscreen_mpr;static	struct icon icon = {64, 64, (struct pixrect *)NULL, 0, 0, 64, 64,	    &lkscr_icpr, 0, 0, 0, 0, NULL, (struct pixfont *)NULL,	    ICON_BKGRDCLR};/* lockscreen choice item choices */static	short jump1_data[256] = {#include <images/jump1.icon>};mpr_static(jump1_mpr, 64, 64, 1, jump1_data);static	short jump2_data[256] = {#include <images/jump2.icon>};mpr_static(jump2_mpr, 64, 64, 1, jump2_data);static	short jump3_data[256] = {#include <images/jump3.icon>};mpr_static(jump3_mpr, 64, 64, 1, jump3_data);static	short jump4_data[256] = {#include <images/jump4.icon>};mpr_static(jump4_mpr, 64, 64, 1, jump4_data);static	short jump5_data[256] = {#include <images/jump5.icon>};mpr_static(jump5_mpr, 64, 64, 1, jump5_data);static	short jump6_data[256] = {#include <images/jump6.icon>};mpr_static(jump6_mpr, 64, 64, 1, jump6_data);static struct pixrect *jump_pr[] = {   &jump1_mpr, &jump2_mpr, &jump3_mpr, &jump4_mpr, &jump5_mpr, &jump6_mpr};#define exit_and_kill(n) { \    if (fg_pid) (void)kill(fg_pid, SIGKILL); \    if (bg_pid) (void)kill(bg_pid, SIGKILL); \    exit(n); \    }static union wait pstatus;static int wpid;char	*tool_get_attribute(), *ttyname(), *sprintf(), *strcpy();long	random();void	wmgr_changestate(), wmgr_top();/* 1025886 vmh: added declarations */    #define MAXLLEN		128		/* max line length */#define MAXPIDS		256		/* max # of console processes */#define SHORTBUFFER	100#define LONGBUFFER	1000static void clear_my_colormap();int get_lockscreen_procs();int get_other_procs();int substring();char * findnextstart();/* 1025886 vmh: end added declarations *//*------------------------------------------------------------------*//* Signal handler for SIGHUP. * Clear the colormap and exit. */ /* 1025886 vmh: added this proc */ static void lockscreen_cleanup(){	register i;	register Pixwin *pixwin = tool->tl_pixwin;	struct screen screen;	char name[WIN_NAMESIZE];	char color[256];	/* calling clear_colormap from here does not work. - why ? */	        /* Lock screen before clear so we don't clobber frame buffer	 * while cursor is moving.         */	(void)pw_lock(pixwin, &screen.scr_rect);        /* Clear available plane groups	 */	(void)win_screenget(tool->tl_windowfd, &screen);	(void)bzero(color, 256);	color[0] = 255;	for (i = 0; i < PIX_MAX_PLANE_GROUPS; i++) {	    if (pixwin->pw_clipdata->pwcd_plane_groups_available[i]) {		/* Write to all plane groups */		(void)pr_set_planes(pixwin->pw_pixrect, i, PIX_ALL_PLANES);		/* Clear screen */		(void)pr_rop(pixwin->pw_pixrect,		    screen.scr_rect.r_left, screen.scr_rect.r_top,		    screen.scr_rect.r_width, screen.scr_rect.r_height,		    PIX_CLR, (Pixrect *)0, 0, 0);		/* Reset "reasonable" colormap */		(void)pr_putcolormap(pixwin->pw_pixrect, 0, 256,		    (unsigned char *)color, 		    (unsigned char *)color, (unsigned char *)color);	    }	}        (void)pw_unlock(pixwin);	exit(0);}/*------------------------------------------------------------------*/static voidsigchild_handler(){    struct timeval TimeVal;    if ((wpid = wait3(&pstatus, WNOHANG, (struct rusage *)0)) > 0) {	if (wpid == fg_pid || wpid == bg_pid) {	    (void)gettimeofday(&TimeVal, (struct timezone *)0);	    if (wpid == fg_pid) {		(void)fprintf (stderr, "foreground process (%s) died at %s",			 fg_prog, ctime((time_t *)(LINT_CAST(&(TimeVal.tv_sec)))));		fg_pid = 0;		*fg_prog = 0;	    } else {		(void)fprintf (stderr, "background process (%s) died at %s",			 bg_prog, ctime((time_t *)(LINT_CAST(&(TimeVal.tv_sec)))));		bg_pid = 0;	    }	}	if (!fg_pid) {	    tooltimer = sectimer;	    tool->tl_io.tio_timer = &tooltimer;	    clear_screen = 1;	}    }}#ifdef STANDALONEmain(argc, argv)#elselockscreen_main(argc, argv)#endif	int argc;	char **argv;{       char	**tool_attrs = NULL;    int k;    int 	uflags;    char *name, *ptr;    char	*getloginname();    struct sigvec vec;    progname = argv[0];       /* 1025886 vmh: program must be named lockscreen.    */    name = argv[0];        if ((ptr = (char *)(strrchr(argv[0], '/'))) != (char *)NULL)         name = (++ptr);	     if (strcmp(name, "lockscreen") != 0)         {	fprintf(stderr, "Cannot rename lockscreen\n");	exit_and_kill(1);	}    /*     * Catch SIGHUP, so we can clean up colormap     */    vec.sv_handler = lockscreen_cleanup;    vec.sv_mask = vec.sv_onstack = 0;    (void)sigvec(SIGHUP, &vec, 0);	    /* 1025886  vmh: end modification */          argv++; argc--;	   /*    * Pick up command line arguments to modify tool behavior    */    if (tool_parse_all(&argc, argv, &tool_attrs, progname) == -1) {	print_help_and_exit();    }    *fg_prog = *bg_prog = 0;	while (argc > 0 && **argv == '-') {		switch (argv[0][1]) {			case 'v':				show_hostname = 1;				break;						case 'e':				exitenable = 1;				break;			case 'r':				rootenable = 1;				break;			case 'b':				if (!*(++argv)) break;  /* Missing name */					(void)expandname(*argv, getpath(), bg_prog);					if (*bg_prog == 0) {						(void)fprintf(stderr,								"Background program (%s) not executable.\n",								*argv);						exit_and_kill(1);					}					argc--;					break;			case 'n':	/* no password */				no_lock = 1;				break;			case 'f':				/* This will exit while loop */				break;			case 't':				if (--argc > 0 && isdigit(**++argv)) timeout = atoi(*argv);				else {					(void)fprintf(stderr, "-t needs integer argument\n");					exit_and_kill(1);				}					break;			case 'H': case 'h': case '?':				print_help_and_exit();			default: /* Unrecognized args are passed to default prog */				*--argv = fg_default, argc++;				argv--;	argc++; /* This is undone at the bottom */				break;		 }		argv++;	argc--;	}    if (argc > 0) {	(void)expandname(*argv, getpath(), fg_prog);	if (*fg_prog == 0 && **argv) {	    (void)fprintf(stderr, "Foreground program (%s) not executable.\n",		    *argv);	    exit_and_kill(1);	} else if (*fg_prog != 0) {	    fg_argv = argv;	    argc = -1;	} else {	    argc = -2; /* No foreground program was set explicitly */	}    }    if (!*fg_prog && argc != -2) {	(void)expandname(fg_default, getpath(), fg_prog);	fg_argv = dummy_argv;	dummy_argv[0] = fg_prog, dummy_argv[1] = 0;    }    if (!*bg_prog) (void)expandname(bg_default, getpath(), bg_prog);    fork_var = *fg_prog || *bg_prog;   /*    * Determine screen size    */    getrectcreate();   /*    * Create tool window    */    icon.ic_width = rectcreate.r_width;    icon.ic_height = rectcreate.r_height;    tool = tool_make(WIN_LABEL,		tool_label,		     WIN_NAME_STRIPE,	0,		     WIN_ICON,		&icon,		     WIN_ATTR_LIST,	tool_attrs,		     WIN_WIDTH,		rectcreate.r_width,		     WIN_HEIGHT,	rectcreate.r_height,		     WIN_LEFT,		rectcreate.r_left,		     WIN_TOP,		rectcreate.r_top,		     WIN_ICON_LEFT,	rectcreate.r_left,		     WIN_ICON_TOP,	rectcreate.r_top,		     WIN_ICONIC,	1,		     0);    if (tool == (struct tool *)NULL) exit_and_kill(1);    (void)tool_free_attribute_list(tool_attrs);    lockscreen_mpr = (struct pixrect *)(LINT_CAST(    	tool_get_attribute(tool, (int)WIN_ICON_IMAGE)));    inittool();    if ((big_font = pf_open(BIG_FONT)) == NULL) {	(void)fprintf(stderr, "lockscreen: Can't find font: %s\n", BIG_FONT);    }    panel_toolsw = panel_create(tool,				PANEL_FONT, big_font, 				PANEL_TIMER_PROC, make_twinkle,				PANEL_LABEL_BOLD, TRUE,				0);    initpanel(panel_toolsw);    /* added to disable L5 (expose/hide) function key */    disable_wmgr_keys(panel_toolsw->ts_windowfd);    disable_wmgr_keys(tool->tl_windowfd);    /* (void)signal(SIGWINCH, sigwinchcatcher); */    vec.sv_handler = sigwinchcatcher;    vec.sv_mask = vec.sv_onstack = 0;    sigvec(SIGWINCH, &vec, 0);    (void)tool_install(tool);    uflags = win_getuserflags(tool->tl_windowfd);    (void)win_setuserflags(tool->tl_windowfd, uflags | WUF_WMGR4);   /*     * setting up the color map must be done AFTER    * doing a tool_install    */    (void)sprintf(cmsname, "lockscreen%d", getpid());    (void)pw_setcmsname(tool->tl_pixwin, cmsname);    for(k = 0; k < CMSIZE-2; k++)	hsv_to_rgb((360/(CMSIZE-2))*k, 255, 255,		   &red[k+1], &green[k+1], &blue[k+1]);    red[0] = green[0] = blue[0] = 255;    red[CMSIZE-1] = green[CMSIZE-1] = blue[CMSIZE-1] = 0;    (void)pw_putcolormap(tool->tl_pixwin, 0, CMSIZE, red, green, blue);    colormonitor = tool->tl_pixwin->pw_pixrect->pr_depth > 1;#ifndef SUN2.0 INPUT_FOCUS   /* Direct keyboard input to tool */    (void)win_set_kbd_focus(tool->tl_windowfd, win_fdtonumber(tool->tl_windowfd));#endif   /* Wait for input */    (void)tool_select(tool, 0/* Dont wait for child process to die */);    (void)tool_destroy(tool);    exit(0);}staticdisable_wmgr_keys(windowfd)	int windowfd;{    struct inputmask mask;    int designee;    win_getinputmask(windowfd, &mask, &designee);    win_unsetinputcodebit(&mask, KEY_LEFT(5));    win_unsetinputcodebit(&mask, KEY_LEFT(7));    win_setinputmask(windowfd, &mask, 0, designee);}statictoolselected(tool_local, ibits, obits, ebits, timer)	struct	tool *tool_local;	int	*ibits, *obits, *ebits;	struct	timeval **timer;{       extern char **environ;    char WinName [80];    int k;    struct sigvec vec;	    wmgr_top(tool_local->tl_windowfd, parentfd);    if (clear_screen) {	(void)pw_writebackground(tool_local->tl_pixwin,			   rectcreate.r_left, rectcreate.r_top,			   rectcreate.r_width, rectcreate.r_height, PIX_SET);	clear_screen = 0;    }    if (fork_var &&	*timer && ((*timer)->tv_sec == 0) && ((*timer)->tv_usec == 0)	&& tool_local->tl_flags & TOOL_ICONIC) {	if (!fg_pid && *fg_prog) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -