Repository: buildbot/buildbot

Issue:
buildbot.tac - use an 0o prefix for octal integers
After fresh installation of buildbot workers on Rocky9 with python 3.9 we found the following problem starting the workers:

```
worker not running
Unhandled Error
Traceback (most recent call last):
  File "/home/bb-slave/lib/python3.9/site-packages/twisted/application/app.py", line 674, in run
    runApp(config)
  File "/home/bb-slave/lib/python3.9/site-packages/twisted/scripts/twistd.py", line 29, in runApp
    runner.run()
  File "/home/bb-slave/lib/python3.9/site-packages/twisted/application/app.py", line 370, in run
    self.application = self.createOrGetApplication()
  File "/home/bb-slave/lib/python3.9/site-packages/twisted/application/app.py", line 437, in createOrGetApplication
    application = getApplication(self.config, passphrase)
--- <exception caught here> ---
  File "/home/bb-slave/lib/python3.9/site-packages/twisted/application/app.py", line 446, in getApplication
    application = service.loadApplication(filename, style, passphrase)
  File "/home/bb-slave/lib/python3.9/site-packages/twisted/application/service.py", line 404, in loadApplication
    application = sob.loadValueFromFile(filename, "application")
  File "/home/bb-slave/lib/python3.9/site-packages/twisted/persisted/sob.py", line 176, in loadValueFromFile
    codeObj = compile(data, filename, "exec")
builtins.SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers (buildbot.tac, line 32)


Failed to load application: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers (buildbot.tac, line 32)
```
it turns out that the umask line in the generated buildbot.tac file causes the trouble:

```
[moko:/home/bb-slave] cat moko_linux_gtk3_slave/buildbot.tac
...
umask = 022
...
```
after changing the line, the worker starts and runs without problems:

```
umask = 0o022
```


Discussion:
[moko:/home/bb-slave] python -V
Python 3.9.16

Hi.
What command did you use for creating the worker?
Because `buildbot-worker create-worker --umask=0o22 ...` works fine for me.
Also `buildbot-worker create-worker --umask=18 ...` would work the same.

Docs: https://docs.buildbot.net/current/manual/installation/worker.html#cmdoption-buildbot-worker-create-worker-umask
Hello vibbo
Worker was created with following commands on Rocky9:
```
yum install python-virtualenv
virtualenv --python=python3 /home/bb-slave
pip install --upgrade pip
pip install buildbot-worker
pip install meson
pip install libxml2-python3

bin/buildbot-worker create-worker \
    --allow-shutdown="signal" \
    --maxdelay=60 \
    --umask=022 \
    moko_linux_gtk3_slave \
    moko "moko-linux-gtk3-slave" "xxxxxxxxxx"
```
So that explains it.
We will fix our creation scripts.

Thanks for helping to find the cause.
fp

Resolving patch:
diff --git a/worker/buildbot_worker/scripts/runner.py b/worker/buildbot_worker/scripts/runner.py
--- a/worker/buildbot_worker/scripts/runner.py
+++ b/worker/buildbot_worker/scripts/runner.py
@@ -217,7 +217,7 @@ def postOptions(self):
                                        argument))
 
         for argument in ["log-count", "maxretries", "umask", "numcpus"]:
-            if not re.match(r'^(0o)?\d+$', self[argument]) and \
+            if not re.match(r'^((0o)\d+|0|[1-9]\d*)$', self[argument]) and \
                     self[argument] != 'None':
                 raise usage.UsageError("{} parameter needs to be a number"
                                     " or None".format(argument))


Test patch:
diff --git a/worker/buildbot_worker/test/unit/test_scripts_runner.py b/worker/buildbot_worker/test/unit/test_scripts_runner.py
--- a/worker/buildbot_worker/test/unit/test_scripts_runner.py
+++ b/worker/buildbot_worker/test/unit/test_scripts_runner.py
@@ -244,6 +244,11 @@ def test_inv_umask(self):
                                "umask parameter needs to be a number or None"):
             self.parse("--umask=X", *self.req_args)
 
+    def test_inv_umask2(self):
+        with self.assertRaisesRegex(usage.UsageError,
+                               "umask parameter needs to be a number or None"):
+            self.parse("--umask=022", *self.req_args)
+
     def test_inv_allow_shutdown(self):
         with self.assertRaisesRegex(usage.UsageError,
                        "allow-shutdown needs to be one of 'signal' or 'file'"):