Re: [PATCH 6/8] Add an autologin feature

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Apr 28, 2011 at 04:56:34PM +0200, Werner Fink wrote:
> -	static struct options options = {
> -		F_ISSUE,	/* show /etc/issue (SYSV_STYLE) */
> -		0,		/* no timeout */
> -		_PATH_LOGIN,	/* default login program */
> -		"tty1",		/* default tty line */
> -		0,		/* line of virtual console */
> -		DEFAULT_VCTERM,	/* terminal type */
> -		"",		/* modem init string */
> -		ISSUE,		/* default issue file */
> -		0, 		/* no baud rates known yet */
> -		{ 0 }
> -	};
> +	static struct options options;
>  	struct sigaction sa, sa_hup, sa_quit, sa_int;
>  	sigset_t set;
>  
> +	options.flags  =  F_ISSUE;		/* show /etc/issue (SYSV_STYLE) */
> +	options.login  =  _PATH_LOGIN;		/* default login program */
> +	options.logopt = "-- \\u";		/* escape for user name */
> +	options.tty    = "tty1";		/* default tty line */
> +	options.term   =  DEFAULT_VCTERM;	/* terminal type */
> +	options.issue  =  ISSUE;		/* default issue file */

 or ideally designated initializer:

   struct options options = {
      .flags  = F_ISSUE;
      .login  =  _PATH_LOGIN;

      ...
   };

 and if I good remember C99 standard then the "static" should be
 unnecessary because remainder of the struct is set of zero in 
 this case.

> +		if (ioctl(STDIN_FILENO, KDGKBLED, &kb) == 0) {
> +			char warn[128];
> +			off_t len = 0;
> + 
> +			if (nl && (kb & 0x02) == 0) {
> +				strcpy(&warn[0], "Num Lock off");
> +				len += 12;
> +			} else if (nl == 0 && (kb & 2) && (kb & 0x20) == 0) {
> +				strcpy(&warn[0], "Num Lock on");
> +				len += 11;
> +			}
> + 
> +			if ((kb & 0x04) && (kb & 0x40) == 0) {
> +				if (len) {
> +					strcpy(&warn[len], ", ");
> +					len += 2;
> +				}
> +				strcpy(&warn[len], "Caps Lock on");
> +				len += 12;
> +			}
> + 
> +			if ((kb & 0x01) && (kb & 0x10) == 0) {
> +				if (len) {
> +					strcpy(&warn[len], ", ");
> +					len += 2;
> +				}
> +				strcpy(&warn[len], "Scroll Lock on");
> +				len += 14;
> +			}
> + 
> +			if (len)
> +				printf ("Hint: %s\n\n", warn);
> +		}

 You have to use _() (gettext) for the strings and don't compose the
 final string from substrings -- it does not have to work for all
 languages. Yeah, I hate it too...

> +static void checkname(const char* nm)
> +{
> +	const char *p = nm;
> +	if (!nm)
> +	goto err;
> +	if (strlen (nm) > 42)
> +	goto err;
> +	while (isspace (*p))
> +	p++;
> +	if (*p == '-')
> +	goto err;
> +	return;
> +err:
> +	errno = EPERM;
> +	error ("checkname: %m");
> +}

 somehow the indentation is lost :-)

> +
> +static void replacename(char** arr, const char* nm)
> +{
> +	const char *p;
> +	char *tmp;
> +	while ((p = *arr)) {
> +	const char *p1 = p;
> +	while (*p1) {
> +		if (memcmp (p1, "\\u", 2) == 0) {
> +			tmp = malloc (strlen (p) + strlen (nm));
> +			if (!tmp)
> +				error ("replacename: %m");
> +			if (p1 != p)
> +				memcpy (tmp, p, (p1-p));
> +			*(tmp + (p1-p)) = 0;
> +			strcat (tmp, nm);
> +			strcat (tmp, p1+2);
> +			*arr = tmp;
> +		}
> +		p1++;
> +	}
> +	arr++;
> +}
> +}
> +
> +static void mkarray(char** arr, char* str)
> +{
> +	char* p = str;
> +	char* start = p;
> +	int i = 0;
> +
> +	while (*p && i < (ARRAY_SIZE_MAX - 2)) {
> +	if (isspace (*p)) {
> +		*p = 0;
> +		while (isspace (*++p))
> +			;
> +		if (*p) {
> +			arr[i++] = start;
> +			start = p;
> +		}
> +	} else
> +		p++;
> +	}
> +	arr[i++] = start;
> +	arr[i++] = (char*)0;
> +}

 Is documented that each word is separate option and the maximal number
 of the options is ARRAY_SIZE_MAX - 2 ?


-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux