Skip to content

Instantly share code, notes, and snippets.

@rewitt1
rewitt1 / gist:20a76f01ca3a4c465628240408173b5c
Created August 22, 2018 17:51
Example of why getting strings from find_library() objects would be useful
***********************************************
Example of the error asan gives when you run an app linked against it and use LD_PRELOAD
***********************************************
LD_PRELOAD=./test/libmock_syscalls.so ./src/myapp
==34946==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.
***********************************************
Example of how you can make asan happy
***********************************************
LD_PRELOAD=libasan.so.5:./test/libmock_syscalls.so ./src/myapp
#!/usr/bin/env python
# webhook.py
#
# Copyright (C) 2016 Intel Corporation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
@rewitt1
rewitt1 / logging.py
Created June 6, 2016 21:01
logging class boilerplate
import logging
ch = logging.StreamHandler()
formatter = logging.Formatter('%(levelname)s:%(message)s')
ch.setFormatter(formatter)
logger = logging.getLogger(__name__)
logger.addHandler(ch)
def _safe_append(filename, workspacedir, data):
"""Safely add data to a file to prevent corruption in the case of """
"""power failure. """
fd, tmp = tempfile.mkstemp(prefix='tmpfile', dir=workspacedir)
try:
# close it and open it again so that "with" can be used
os.close(fd)
shutil.copyfile(filename, tmp)
with open(tmp, 'a') as f:
f.write(data)