be loud about segfaults and such

This commit is contained in:
ed 2022-05-12 20:26:48 +02:00
parent 2fb46551a2
commit 214a367f48
6 changed files with 60 additions and 10 deletions

View file

@ -18,6 +18,7 @@ from .httpcli import HttpCli
from .u2idx import U2idx from .u2idx import U2idx
from .th_cli import ThumbCli from .th_cli import ThumbCli
from .th_srv import HAVE_PIL, HAVE_VIPS from .th_srv import HAVE_PIL, HAVE_VIPS
from .mtag import HAVE_FFMPEG
from .ico import Ico from .ico import Ico
@ -38,7 +39,7 @@ class HttpConn(object):
self.cert_path = hsrv.cert_path self.cert_path = hsrv.cert_path
self.u2fh = hsrv.u2fh self.u2fh = hsrv.u2fh
enth = (HAVE_PIL or HAVE_VIPS) and not self.args.no_thumb enth = (HAVE_PIL or HAVE_VIPS or HAVE_FFMPEG) and not self.args.no_thumb
self.thumbcli = ThumbCli(hsrv) if enth else None self.thumbcli = ThumbCli(hsrv) if enth else None
self.ico = Ico(self.args) self.ico = Ico(self.args)

View file

@ -8,7 +8,7 @@ import shutil
import subprocess as sp import subprocess as sp
from .__init__ import PY2, WINDOWS, unicode from .__init__ import PY2, WINDOWS, unicode
from .util import fsenc, fsdec, uncyg, runcmd, REKOBO_LKEY from .util import fsenc, fsdec, uncyg, runcmd, retchk, REKOBO_LKEY
from .bos import bos from .bos import bos
@ -82,8 +82,9 @@ def ffprobe(abspath, timeout=10):
b"--", b"--",
fsenc(abspath), fsenc(abspath),
] ]
rc = runcmd(cmd, timeout=timeout) rc, so, se = runcmd(cmd, timeout=timeout)
return parse_ffprobe(rc[1]) retchk(rc, cmd, se)
return parse_ffprobe(so)
def parse_ffprobe(txt): def parse_ffprobe(txt):
@ -491,12 +492,14 @@ class MTag(object):
cmd = ["nice"] + cmd cmd = ["nice"] + cmd
cmd = [fsenc(x) for x in cmd] cmd = [fsenc(x) for x in cmd]
v = sp.check_output(cmd, **args).strip() rc, v, err = runcmd(cmd, **args)
retchk(rc, cmd, err, self.log, 5)
v = v.strip()
if not v: if not v:
continue continue
if "," not in tagname: if "," not in tagname:
ret[tagname] = v.decode("utf-8") ret[tagname] = v
else: else:
v = json.loads(v) v = json.loads(v)
for tag in tagname.split(","): for tag in tagname.split(","):

View file

@ -343,6 +343,8 @@ class ThumbSrv(object):
def conv_ffmpeg(self, abspath, tpath): def conv_ffmpeg(self, abspath, tpath):
ret, _ = ffprobe(abspath) ret, _ = ffprobe(abspath)
if not ret:
return
ext = abspath.rsplit(".")[-1].lower() ext = abspath.rsplit(".")[-1].lower()
if ext in ["h264", "h265"] or ext in self.fmt_ffi: if ext in ["h264", "h265"] or ext in self.fmt_ffi:

View file

@ -9,6 +9,7 @@ import time
import base64 import base64
import select import select
import struct import struct
import signal
import hashlib import hashlib
import platform import platform
import traceback import traceback
@ -1350,8 +1351,8 @@ def guess_mime(url, fallback="application/octet-stream"):
return ret return ret
def runcmd(argv, timeout=None): def runcmd(argv, timeout=None, **ka):
p = sp.Popen(argv, stdout=sp.PIPE, stderr=sp.PIPE) p = sp.Popen(argv, stdout=sp.PIPE, stderr=sp.PIPE, **ka)
if not timeout or PY2: if not timeout or PY2:
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
else: else:
@ -1366,9 +1367,10 @@ def runcmd(argv, timeout=None):
return [p.returncode, stdout, stderr] return [p.returncode, stdout, stderr]
def chkcmd(argv): def chkcmd(argv, **ka):
ok, sout, serr = runcmd(argv) ok, sout, serr = runcmd(argv, **ka)
if ok != 0: if ok != 0:
retchk(ok, argv, serr)
raise Exception(serr) raise Exception(serr)
return sout, serr return sout, serr
@ -1385,6 +1387,46 @@ def mchkcmd(argv, timeout=10):
raise sp.CalledProcessError(rv, (argv[0], b"...", argv[-1])) raise sp.CalledProcessError(rv, (argv[0], b"...", argv[-1]))
def retchk(rc, cmd, serr, logger=None, color=None):
if rc < 0:
rc = 128 - rc
if rc < 126:
return
s = None
if rc > 128:
try:
s = str(signal.Signals(rc - 128))
except:
pass
elif rc == 126:
s = "invalid program"
elif rc == 127:
s = "program not found"
else:
s = "invalid retcode"
if s:
m = "{} <{}>".format(rc, s)
else:
m = str(rc)
try:
c = " ".join([fsdec(x) for x in cmd])
except:
c = str(cmd)
m = "error {} from [{}]".format(m, c)
if serr:
m += "\n" + serr
if logger:
logger(m, color)
else:
raise Exception(m)
def gzip_orig_sz(fn): def gzip_orig_sz(fn):
with open(fsenc(fn), "rb") as f: with open(fsenc(fn), "rb") as f:
f.seek(-4, 2) f.seek(-4, 2)

View file

@ -59,6 +59,7 @@ class Cfg(Namespace):
theme=0, theme=0,
themes=0, themes=0,
turbo=0, turbo=0,
logout=573,
hist=None, hist=None,
no_idx=None, no_idx=None,
no_hash=None, no_hash=None,

View file

@ -39,6 +39,7 @@ class Cfg(Namespace):
"theme": 0, "theme": 0,
"themes": 0, "themes": 0,
"turbo": 0, "turbo": 0,
"logout": 573,
} }
ex.update(ex2) ex.update(ex2)
super(Cfg, self).__init__(a=a or [], v=v or [], c=c, **ex) super(Cfg, self).__init__(a=a or [], v=v or [], c=c, **ex)