Alright. Thanks all for replying. I’m really having a time with this, and am “learning by doing”.
First: The variable I’m using is USER. Which, to my understanding, is set upon login. By some process, I know not the name of.
I want it to create, or modify a simple two line text file that will be used to mount two cifs network drives.
A section of the code, in C, follows:
/* ************************************ */
/* Figure out who's logged in. */
/* ************************************ */
pUser = getenv("USER");
if (showdebug)
printf( "pUser = %s
", pUser);
/* ***************************************************** */
/* Set the string that will go into the credentials file. */
/* ***************************************************** */
//
if (strcmp(pUser,"robert") == 0)
out_string = "username=robert
password=123456789
";
else if (strcmp(pUser,"joseph") == 0)
out_string = "username=joseph
password=987654321
";
else if (strcmp(pUser,"henry") == 0)
out_string = "username=henry
password=444444444
";
else {
/* ******************************************** */
/* If username is nonvalid, do no mount drives. */
/* ******************************************** */
out_string = "username=nonvalid
password=nonvalid
";
call_mount = 1;
}
if (showdebug)
printf( "out_string = %s
", out_string);
/* ************************************ */
/* Write the file. */
/* ************************************ */
FILE *out_file;
if ( ( out_file = fopen( FILE_NAME, "w+" ) ) == NULL )
exit (errno);
fputs( out_string, out_file );
fclose( out_file );
After this, I use fork() / wait()/ execl() to mount the drives.
This program compiles without errors or warnings and works as I want it to from an instance of konsole. But of course, the desktop and environment has been stabilized. When rebooting, it always writes the “nonvalid” lines, indicating that the USER environment variable has not been set.
I am not an accomplished C programmer, and am still a novice with the linux system internals. I encourage any critique on my code, style or choice of commands.
That all said,
A desktop file in /etc/xdg/autostart should suffice…?
as posted by malcolmlewis works and is actually what I was looking for. Now, if I could just find the location of the documentation for that, I won’t ever have to ask again.