Edgewall Software
Modify

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#13336 closed defect (fixed)

tracd 1.5.2 --daemonize fails, "TypeError: an integer is required (got type str)"

Reported by: stu-trac-@… Owned by: Jun Omae
Priority: normal Milestone: 1.5.3
Component: general Version: 1.5.2
Severity: normal Keywords:
Cc: Branch:
Release Notes:

Fixed -d/--daemonize failure for tracd.

API Changes:
Internal Changes:

Description (last modified by Ryan J Ollos)

[17483/trunk/trac/util/daemon.py] changed daemonize from open to os.open, but didn't convert from Python 'rb' and 'ab+' to os.open flags, result of trying to run tracd -d is:

Traceback (most recent call last):
  File "/usr/local/bin/tracd", line 11, in <module>
    load_entry_point('Trac==1.5.2', 'console_scripts', 'tracd')()
  File "/usr/local/lib/python3.8/site-packages/trac/web/standalone.py", line 366, in main
    daemon.daemonize(pidfile=args.pidfile, progname='tracd',
  File "/usr/local/lib/python3.8/site-packages/trac/util/daemon.py", line 71, in daemonize
    stdin = os.open(stdin, 'rb')
TypeError: an integer is required (got type str)

Attachments (0)

Change History (5)

comment:1 by Ryan J Ollos, 4 years ago

Description: modified (diff)
Milestone: 1.5.3

comment:2 by Ryan J Ollos, 4 years ago

Owner: set to Ryan J Ollos
Status: newassigned

os.open requires integer flags. This change seems to work. What do you think, Jun?

  • trac/util/daemon.py

    diff --git a/trac/util/daemon.py b/trac/util/daemon.py
    index cc7c0d61e4..64d8ad999f 100644
    a b def daemonize(pidfile=None, progname=None, stdin='/dev/null',  
    6868    # The process is now daemonized, redirect standard file descriptors
    6969    for stream in sys.stdout, sys.stderr:
    7070        stream.flush()
    71     stdin = os.open(stdin, 'rb')
    72     stdout = os.open(stdout, 'ab+')
    73     stderr = os.open(stderr, 'ab+', 0)
     71    stdin = open(stdin, 'rb')
     72    stdout = open(stdout, 'ab+')
     73    stderr = open(stderr, 'ab+', 0)
    7474    os.dup2(stdin.fileno(), sys.stdin.fileno())
    7575    os.dup2(stdout.fileno(), sys.stdout.fileno())
    7676    os.dup2(stderr.fileno(), sys.stderr.fileno())

I tried switching to integer flags for os.open, but then:

Traceback (most recent call last):
  File "/Users/rjollos/.pyenv/versions/trac-py386/bin/tracd", line 33, in <module>
    sys.exit(load_entry_point('Trac', 'console_scripts', 'tracd')())
  File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/web/standalone.py", line 366, in main
    daemon.daemonize(pidfile=args.pidfile, progname='tracd',
  File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/util/daemon.py", line 80, in daemonize
    os.dup2(stdin.fileno(), sys.stdin.fileno())
AttributeError: 'int' object has no attribute 'fileno'

comment:3 by Jun Omae, 4 years ago

Ah, the changes in [d373b6ded/jomae.git] (log:jomae.git@1.5-py3) was incomplete.

The intention of the using os.open() is that avoiding text/binary mode for built-in open() because it just wants to get file descriptors for os.dup2() with std{in,out,err}.

Of course, your suggested changes are correct.

  • trac/util/daemon.py

    diff --git a/trac/util/daemon.py b/trac/util/daemon.py
    index cc7c0d61e..7b49bcfdf 100644
    a b def daemonize(pidfile=None, progname=None, stdin='/dev/null',  
    6868    # The process is now daemonized, redirect standard file descriptors
    6969    for stream in sys.stdout, sys.stderr:
    7070        stream.flush()
    71     stdin = os.open(stdin, 'rb')
    72     stdout = os.open(stdout, 'ab+')
    73     stderr = os.open(stderr, 'ab+', 0)
    74     os.dup2(stdin.fileno(), sys.stdin.fileno())
    75     os.dup2(stdout.fileno(), sys.stdout.fileno())
    76     os.dup2(stderr.fileno(), sys.stderr.fileno())
     71    stdin = os.open(stdin, os.O_RDONLY)
     72    stdout = os.open(stdout,  os.O_RDWR | os.O_APPEND)
     73    stderr = os.open(stderr, os.O_RDWR | os.O_APPEND)
     74    os.dup2(stdin, sys.stdin.fileno())
     75    os.dup2(stdout, sys.stdout.fileno())
     76    os.dup2(stderr, sys.stderr.fileno())
     77    for fd in (stdin, stdout, stderr):
     78        os.close(fd)
    7779
    7880    if pidfile:
    7981        # Register signal handlers to ensure atexit hooks are called on exit

comment:4 by Ryan J Ollos, 4 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Thanks, Jun. Fixed in r17497.

comment:5 by Ryan J Ollos, 4 years ago

Owner: changed from Ryan J Ollos to Jun Omae

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.