Autostart locations

After finally figuring out how to code the little utility I wanted, I am trying to find the correct location and/or internal settings to make it work the way I want.
My utility is an executable program that uses the USER environment variable to make a decision. I have placed a .desktop file in /usr/share/autostart but it apparently gets run before the environment is set up. I moved to file to ~/config/autostart and it works, but of course, that would require that each user have a copy of the desktop file in their autostart directory, and then duplicated in wherever Gnome wants it’s startup files. That’s a lot of duplication!

Using a link to the .desktop file might work but then again, a lot of duplication.

I went to kde.org but was unable to find any documentation on the lines: X-KDE-autostart-* or actually any of the lines that make up a .desktop file. And then, I’m not sure Gnome would use the X-KDE- lines in an autostart file.

I could sure use some help with the correct/acceptable method of doing this.

Bart

What environment do you expect to be set up? You probably will need to give more details what is missing.

I usually use kde, but as I said, I sometimes use Gnome. Anything else and I don’t mind mounting as root.

Hm, it may be me, but I have the impression that you expect others to have much more knowledge about what you are doing and wanting then they have in reality. Do not assume any knowledge and do not jump steps in describing what you want. Handle it as if you are the only one in the world that wants this feature (whatever it may be).

Also I get the strong impression that this is a typical case of “Describe the goal, not the step” as explained in http://www.catb.org/~esr/faqs/smart-questions.html#goal, which btw also has other usfull hints.

What I understand from the above is that you want to run a program (written by you) to be run every time a user logs in in your system. I understand that you want this to be done irrespective of the DE used on the login (but It is not clear to me if it should also be done on loging in in the CLI). Please confirm, or better comment on this or replace my guess by a better exact description.

I may however be completely wrong on what I understand, e.g. your last remark about “Anything else and I don’t mind mounting as root.” does not fit into my guesses at all. Mounting what, where and what for???

It may also be that others understand you and that I am the only dumb one, but avidjaar’s ppost seems to confirm my ideas.

I guess after creating the application, I make assumptions that I was being clearer than I was.

My application uses an environment variable to do it’s job.
I want the application to run automatically upon login, regardless of the DM.
I normally use kde, but ocasionally use Gnome. Hadn’t given CLI any thought, but don’t need it at CLI.
Everything I have tried runs the application before the environment is set, thereby giving me erroneous values.

I’m aware I was being a little evasive about the workings of the application as I was trying to not ask for specifics about coding. I have spend some time trying to find documentation about how to do what I want, but simply cannot find it on either the openSuse documentation site nor the kde site. I would refer to the parameters in a .desktop file such as X-KDE-autostart-phase=2. Where do I find what phases there are? and what they mean? About -condition? And X-KDE-autostart-after-panel, which seems to have changed from plasma. Where would I find which to use? And, what about the location for autostarting a process under Gnome? I can’t find anything about that.

Yes, I am describing the goal. The easiest answer in this case would be that someone replied with “This is the parameter that will cause the file to be run after kde and or Gnome have been finished loading and the environment is stable.” But better would be a reply that listed the search string and a link to the documentation. I really don’t know how to word my request any different.

  1. Depending on what the solution might be, you may be forced to check if it is a CLI login and then acting to that (by skipping further execution of the program).
  2. “before the environment is set,” might be sloppy expressing yourself, but it could also point to misunderstanding. The process environment, including variables therein is allways present in the meaning that each and every process has one. What is in there (which variables are defined and what their values are) differs of course per process and even during the existance of a process. Thus this is not “before the environment is set”, but before a certain variable (USER I assume) is set. Did you check which processes set and or change USER? And if such a process is one of the (grand-)parents of your process? Without knowing this, you might be surprised by the results (as you are in fact).
  3. “after kde and or Gnome have been finished loading”. I am not sure such a fixed point exists (may depend on the DE). After login validation, the desktop starts several processes, some are done always, some depend on user configurations. Some will do what they should do and then finish, some will be active until logout. They will basicaly run parallel to each other. At any time the user may start clicking on things he already sees on the screen and thus start new processes. There will be ongoing activity. No point at which the desktop is “ready to be used” (at may look like that to you as user when you do nothing after login until you “think” that “|everthing is now there”).

I think you should think over what you want (that still being a secret I can give no advice on that).

When your process wants to know under which user it is running (I guess that is what you hope to find out by using the process environment variable USER), look for a better defined way of doing this. Again, as the language you used in programming your tool is a secret, I can only suggest commands that can be used in e.g. a shell. When you use e.g. C, you mus find the equivalent library calls yourself.
For tools, look at

id

and

whoami

How and where this environment variable is set?

On Wed 25 May 2016 09:26:02 AM CDT, montana suse user wrote:

I guess after creating the application, I make assumptions that I was
being clearer than I was.

My application uses an environment variable to do it’s job.
I want the application to run automatically upon login, regardless of
the DM.
I normally use kde, but ocasionally use Gnome. Hadn’t given CLI any
thought, but don’t need it at CLI.
Everything I have tried runs the application before the environment is
set, thereby giving me erroneous values.

I’m aware I was being a little evasive about the workings of the
application as I was trying to not ask for specifics about coding. I
have spend some time trying to find documentation about how to do what I
want, but simply cannot find it on either the openSuse documentation
site nor the kde site. I would refer to the parameters in a .desktop
file such as X-KDE-autostart-phase=2. Where do I find what phases there
are? and what they mean? About -condition? And
X-KDE-autostart-after-panel, which seems to have changed from plasma.
Where would I find which to use? And, what about the location for
autostarting a process under Gnome? I can’t find anything about that.

Yes, I am describing the goal. The easiest answer in this case would be
that someone replied with “This is the parameter that will cause the
file to be run after kde and or Gnome have been finished loading and the
environment is stable.” But better would be a reply that listed the
search string and a link to the documentation. I really don’t know how
to word my request any different.

Hi
A desktop file in /etc/xdg/autostart should suffice…?


Cheers Malcolm °¿° LFCS, SUSE Knowledge Partner (Linux Counter #276890)
openSUSE Leap 42.1|GNOME 3.16.2|4.1.20-11-default
If you find this post helpful and are logged into the web interface,
please show your appreciation and click on the star below… Thanks!

To the OP,

You first need to identify and define the dependencies for your script.
From what you’ve described, you’re just trying various startups and discovering whether your scripts works by trial and error, You can do that, but you can find a better and optimal way to invoke your script only by understanding what has to exist before your script can run.

Can you at least list your dependencies even if you won’t post the script itself?

You can invoke your script in .desktop, I’d be surprised if you can’t specify the dependency you need, <or> simply move the code block down, perhaps to the end of the file. AFAIK like most config files, the file is read from top to bottom, so if at the bottom your script should execute only after all before it has run. Read the .desktop file documentation on this instead of merely inserting your code block and giving up. Using “.desktop” should work in any KDE or Gnome desktops, but YMMV in any other.

TSU

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.

OK,
Mounting drives has been a common topic recently in a number of forums, besides this one in “Programming and Scripting” there are other very recent threads in Installing, Applications and Networking…

Here’s my recommendation…

  1. Set up Network Manager instead of Wicked networking, by default (and unless you check the box to start on boot) this does not start until after the User has logged in and then uses network credentials specific to that User (often stored in KWallet if KDE is the desktop).

2, Once you are certain your mounting application (which can be written in any number of ways including C), create a systemd Unit file that specifies the Network Manager service as a dependency (requires).

This ensures that not only your $USER variable is valid, your networking is also up and running to support a remote network connection.

There are of course other ways to mount network drives automatically.
One of the other Forum threads described another way that creates an assigned disk or directory in fstab which is not mounted immediately on boot, actual mounting is made when the User first attempts a connection.

TSU

Ah! Now, with the benefit of hindsight, I see my problem: I was locked into “doing it my way” instead of looking for an answer to what I was trying to do. Using network manager appears to be a more secure way of doing this, and would work well I’m sure.

That said, I learned something :open_mouth: , something about the internal workings of the system, and about the C language.

Thanks all! You guys, and your willingness to put up with people like me, are what makes openSUSE great!

Bart

That is what I pointed to as “Explain the goal, not the step”.

Human beings tend to walk a path, and when one or two steps seem promising, they keep going their until they got realy stuck. Then they ask others " why can’t I walk on here?". The answer is in fact: “because you are on the wrong path”. Most human beings find it difficult to see that, admit to themselves that they did it wrong and start all over again. This has nothing to do with computers specificaly, it happens in all aspects of life.