bugGNU Octave - Bugs: bug #48017, --no-window-system command line...

 
 

bug #48017: --no-window-system command line option does not disable graphics

Submitter:  Rik <rik5>
Submitted:  Wed 25 May 2016 05:25:25 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 27 May 2016 04:48:57 PM UTC, comment #6: 

I combined our two modifications in to one cset that resolves this bug (http://hg.savannah.gnu.org/hgweb/octave/rev/58a4c5633efd).  Fixed, closing report.

Rik <rik5>
Group administrator
Wed 25 May 2016 10:33:01 PM UTC, comment #5: 

Maybe the attached diff could address the gnuplot default terminal when --no-window-system is in use.

(file #37265)

Mike Miller <mtmiller>
Group Member
Wed 25 May 2016 07:53:35 PM UTC, comment #4: 

Yeah, good point. This gets complicated quickly. I think you're right that it should launch the cli executable, which unfortunately means handling a subset of options twice like this.

After I run octave-cli --no-window-system, I get the following


>> get (0, "screensize")
ans =
   1   1   1   1
>> have_window_system
ans = 0


so the display_info looks to be initialized correctly there. I don't know why the size vector is all 1s instead of 0s, but it is correctly not returning my actual display size.

Mike Miller <mtmiller>
Group Member
Wed 25 May 2016 06:11:55 PM UTC, comment #3: 

Attached is a patch which fixes up main.in.cc to handle the -W option.  This is a first step.  The octave-cli is now called correctly and the graphics_toolkit is set to gnuplot.  But it still thinks there is a display available because it is not producing ascii art.

(file #37262)

Rik <rik5>
Group administrator
Wed 25 May 2016 05:57:05 PM UTC, comment #2: 

Our startup mechanism is so convoluted now that I'm not always sure what is going on.

I see in src/main.cc the following:


int
main (int argc, char **argv)
{
  int retval = 0;

  bool start_gui = true;
  bool gui_libs = true;

  std::string octave_bindir = get_octave_bindir ();
  std::string octave_archlibdir = get_octave_archlibdir ();
  std::string octave_cli
    = octave_bindir + dir_sep_char + "octave-cli-" OCTAVE_VERSION;
  std::string octave_gui = octave_archlibdir + dir_sep_char + "octave-gui";

#if defined (HAVE_OCTAVE_QT_GUI)
  // The Octave version number is already embedded in the
  // octave_archlibdir directory name so we don't need to append it to
  // the octave-gui filename.

  std::string file = octave_gui;
#else
  std::string file = octave_cli;
#endif

  // Declaring new_argv static avoids leak warnings when using GCC's
  // --address-sanitizer option.
  static char **new_argv = new char * [argc + 1];

  int k = 1;

  bool warn_display = true;

  for (int i = 1; i < argc; i++)
    {
      if (! strcmp (argv[i], "--no-gui-libs"))
        {
          // Run the version of Octave that is not linked with any GUI
          // libraries.  It may not be possible to do plotting or any
          // ui* calls, but it will be a little faster to start and
          // require less memory.  Don't pass the --no-gui-libs option
          // on as that option is not recognized by Octave.

          start_gui = false;
          gui_libs = false;
          file = octave_cli;
        }
      else if (! strcmp (argv[i], "--no-gui"))
        {
          // If we see this option, then we can just exec octave; we
          // don't have to create a child process and wait for it to
          // exit.  But do exec "octave-gui", not "octave-cli", because
          // even if the --no-gui option is given, we may be asked to do
          // some plotting or ui* calls.

          start_gui = false;
          new_argv[k++] = argv[i];
        }
      else if (! strcmp (argv[i], "--silent") || ! strcmp (argv[i], "--quiet")
               || ! strcmp (argv[i], "-q"))
        {
          warn_display = false;
          new_argv[k++] = argv[i];
        }
      else
        new_argv[k++] = argv[i];
    }

  new_argv[k] = 0;

  if (gui_libs || start_gui)
    {
      int dpy_avail;

      const char *display_check_err_msg = display_available (&dpy_avail);

      if (! dpy_avail)
        {
          start_gui = false;
          gui_libs = false;

          file = octave_cli;

          if (warn_display)
            {
              if (! display_check_err_msg)
                display_check_err_msg = "graphical display unavailable";

              std::cerr << "octave: " << display_check_err_msg << std::endl;
              std::cerr << "octave: disabling GUI features" << std::endl;
            }
        }
    }


For starters, I think if a user explicitly sets the --no-window-system option then they don't need to be warned about the lack of a graphical display.  This suggests that the following code needs to be extended to include "--no-window-system" and "-W". 


    else if (! strcmp (argv[i], "--silent") || ! strcmp (argv[i], "--quiet")
               || ! strcmp (argv[i], "-q"))
        {
          warn_display = false;
          new_argv[k++] = argv[i];
        }


Second,


      const char *display_check_err_msg = display_available (&dpy_avail);


Is this call made before, or after, the call to no_window_system()?  If it is made before then it will screw things up.

Rik <rik5>
Group administrator
Wed 25 May 2016 05:34:52 PM UTC, comment #1: 

The option does avoid some things, but not everything. I agree it could be used to do more.

Here's what it does

  • prevent starting the GUI
  • prevent trying to initialize $DISPLAY
  • set up the display_info class so that height, width, dpi all return 0, and display_available returns false


The problem seems to lie in that display_info::display_available should be used in more places.

Making Octave remove DISPLAY from its environment might be one way to go, but I usually dislike modifying the user's environment unless it's absolutely necessary.

Mike Miller <mtmiller>
Group Member
Wed 25 May 2016 05:25:25 PM UTC, original submission:  

The --no-window-system or -W argument is supposed to disable any Octave features which need a graphical display.  However, the following works


octave -f -W
plot (1:10)


Octave can be forced to believe there in no display if you remove the X11 DISPLAY variable from the environment.


unsetenv DISPLAY
octave -f -W
plot (1:10)


The plot is now made only on the console using ASCII art.

This seems to be a problem with input option processing.  In octave.cc there is this line


  if (no_window_system)
    display_info::no_window_system ();


In display.h there is this


  // To disable querying the window system for defaults, this function
  // must be called before any other display_info function.
  static void no_window_system (void)
  {
    instance_ok (false);
  }


My guess is that the order of initialization in octave.cc is now calling something that creates an instance of the display with a value of true before this is called.

Rik <rik5>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #37265:  gnuterm.diff added by mtmiller (455B - text/x-diff)
file #37262:  main.diff added by rik5 (912B - application/x-download)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by rik5 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-05-31 rik5 Open/ClosedOpen Closed
    2016-05-27 rik5 StatusConfirmed Fixed
    2016-05-25 mtmiller Attached File- Added gnuterm.diff, #37265
    2016-05-25 rik5 Attached File- Added main.diff, #37262

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code