Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 19
I have written a program for scada application. I used a script to automatically start it at run-level 5 with $ALL option so that the script starts after other scripts. ...
  1. #1
    Just Joined!
    Join Date
    Jun 2008
    Posts
    16

    Angry xmessage is not working from a start-up-at-boot program

    I have written a program for scada application. I used a script to automatically start it at run-level 5 with $ALL option so that the script starts after other scripts. Now, the program gets executed at boot time. It forks into memory and stays active. It works fine and reports issues to syslog. But, xmessage command does not work!! ie: When the program finds an issue (it connects to scada controller through com port), it has to pop up message and it also has to write to syslog. Writing to syslog works fine, but, popup doesn't work !! Pop up is done using xmesage command. Pop-up works fine if I execute the progeam by doubleclicking on the script, or invoke it in terminal mode. ie: After system boots up, if I manually execute the program, xmessage works fine and the windows pop up. Both the script and the program has 777 as permission attribute. Program owner is root, and I am logging in as root, always. But xmessage doesn't work if the program is part of start-up!! In the script, I have asked the program to be started only ar runlevel 5. Where is the mistake? I am trying it in Suse. Program was written is C. It just invokes system(xmessage(mymsgstring)) . Please help.

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    X applications such as xmessage do not work unless the environment variable DISPLAY is set. At the command line, try this:
    Code:
    echo $DISPLAY
    It should respond with something like:
    Code:
    :0.0
    In your C program, use putenv() or setenv() to set the DISPLAY variable to what you saw when you examined it at the command line.

    This is assuming that X has come up all the way by the time you fire off your first message. Even though all your initialization scripts have completed, that may take a few more seconds.

    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Jun 2008
    Posts
    16

    xmessage doesn't work!!

    Thanks Bill. Kindly clarify the following

    1. Even though I am using xmessage as a shell command, I need to set the environment variables in my C program for the shell command to work properly. Is this right?

    2. The idea is to distribute the program. It will be autostarted after boot, and target machines could be of any Linux flavour. So If I hardcode the environment, will it cause problems? Will the environment values be same for all machines?

    3. Pop-ups wok if I execute the program or script by doubleclicking it, but fail to appear if execution was done by start-up scripts. Is it because the environmental variables are not set when the start-up scripts are executed? (Please note that the script is executed at runlevel 5!!

    4. Is there any other way to have a pop-up?

    Thanking you again, Raj

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Even though I am using xmessage as a shell command, I need to set the environment variables in my C program for the shell command to work properly. Is this right?
    Assuming that you're executing this shell command from your C program, that is correct.
    The idea is to distribute the program. It will be autostarted after boot, and target machines could be of any Linux flavour. So If I hardcode the environment, will it cause problems? Will the environment values be same for all machines?
    It will be the same for 99.9% of all machines, I am sure, unless they're not running X in the first place. (Mine sometimes does not.) In that case, you might have a problem. How do you get error messages to the eyes of people who do not run X? That depends on how they use their machines, and that varies widely. The best you can do is to use sound in some way. And not everyone has a sound card. I don't have one, whether I use X (which is most of the time) or not.
    Is it because the environmental variables are not set when the start-up scripts are executed?
    Correct. Shell scripts are set by your profile files (which can have several names) when you actually log in to your shell.
    Is there any other way to have a pop-up?
    I don't know, but if you are going to have a pop-up on a screen running X, you will always have the same problem of needing DISPLAY to be defined properly.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  5. #5
    Just Joined!
    Join Date
    Jun 2008
    Posts
    16

    Smile

    Could you give some guidance on how to use putenv or setenv? searched a lot but could not get any information on setting the display variable!! It would be great if you could help a bit....

  6. #6
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    This will get you going:
    1. The name of the environment variable is DISPLAY (note that it's all upper case).
    2. For the vast majority of systems out there, you'll want the variable's value to be exactly :0.0
    3. For information on how to use putenv(), do this at the command line:
      Code:
      man putenv
      If man pages are not installed on your system, google this:
      Code:
      linux man putenv
    4. For information on how to use setenv(), do this at the command line:
      Code:
      man setenv
      If man pages are not installed on your system, google this:
      Code:
      linux man setenv
    --
    Bill

    Old age and treachery will overcome youth and skill.

  7. #7
    Just Joined!
    Join Date
    Jun 2008
    Posts
    16

    It is still not working!!

    First, I tried to change the DISPLAY environment in the script.

    I used the command

    env|grep DISPLAY >/dev/null || { DISPLAY=:0.0; export DISPLAY; }

    in the script that is executed by the start-up script and also in the startup script. #!/bin/sh was used for running.

    Script did not give any errors. But xmessage doesn't work!!! No pop ups came!!

    1. I inserted the line " env|grep DISPLAY >/dev/null || { DISPLAY=:0.0; export DISPLAY; } " both in the startup script and the actual script that is run by the startup script.
    2. I also tried removing the second script altogether and directly running the program in the start up script.
    3. I again tried removing the line from the start-up script and using it only in the script run by the startup script.
    4. I further tried running the scripts immediately after booting, ie: in boot.local file.

    But nothing works. Scripts are run at runlevel 5.

    The program works fine except for the xmessage. It reports issues to syslog also correctly. If I kill the program after startup and then execute it again manually, messages also pop up correctly.

    Then I tried modifying the c program. I found out that, even after inserting putenv("DISPLAY=:0.0") in my c program, xmessage doesn't work. Actually, program exits the parent and forks into a daemon that scans the port to which a scada controller is connected. putenv("DISPLAY=:0.0") was inserted at the entry point in the parent, and even in the entry point in the child. program compiles fine without any errors or warnings, but xmessage doesn't work!! Everything else works correctly. But, as I mentioned, if I kill the program after startup and then execute it again manually, messages pop up correctly.

    Any suggestions would be of great help.

  8. #8
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    I'm at a loss here. It looks as though you're doing everything correctly.

    Is there any chance you're trying to use xmessage before X is all the way up?
    --
    Bill

    Old age and treachery will overcome youth and skill.

  9. #9
    Just Joined!
    Join Date
    Jun 2008
    Posts
    16

    Unhappy

    Absolutely not. xmessage is used only later. Actually, it is used only when error conditions are detected. Generally there won't be. I am testing xmessage by simulating error conditions when x is already up desktop is already up and running !!

  10. #10
    Just Joined!
    Join Date
    Jun 2008
    Posts
    16

    Lightbulb May be it is not supposed to work !!

    Forgive me if I am wrong, but I feel like concluding that, xmessage will never work if executed from a program that runs before a user logs in. Because, the xmessage doesn't know to whom it should be displayed to!! Probably this is a stupid thing to say !!

    1. If I do wall in a c program, nothing comes on the screen (unless I am in a terminal, executing the program in terminal mode. Actually, before the program forks into a child, walled messages appear on the terminal. But afterwards, all walls don't appear on the screen, probably because the child program doesn't know to which session the wall messages should be displayed (??!!!). Am I right here? I was wondering again, that the same thing could be happening to xmessage. Since it doesn't know whom to show the message, or in which session to show the message, it doesn't come up!! But when the program is executed manually by doubleclicking it or in the terminal mode, it shows the messages to the current user!! This sounds like nonsense to me, but since it is not showing up, I can't but reach this conclusion!!!
    In the same C program, I tried to execute a script (in the child part, after forking) which has an xmessage "testing". But the message doesn't come up!!

    Please comment and guide...

    Is there a way I can atleast show the message in a terminal window? like wall output?

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...