Yearly Archives: 2017


Make building with cmake verbose 1

Ever wanted to get more information out of a build process controlled by CMake?
We sure did and this is how we did it:

Option 1 – Change your CMakeLists.txt files

As our first option, we present updating your CMakeLists.txt file to include the following configuration line:

set(CMAKE_VERBOSE_MAKEFILE ON)

This option by itself is enough to enable verbosity.
A caveat with this option is that the configuration is not passed on to other CMakeLists.txt files that are included to the build using the command add_subdirectory () from the master CMakeLists.txt file.
Thus, you need to copy the configuration file to each CMakeLists.txt file you want to be verbose.

Option 2 – Add the variable VERBOSE=1 to your make command

Assuming you are using a terminal and you are in the folder where you want to build your project.
After you execute the command

cmake $path_to_project_source;

execute your make command using the VERBOSE=1 variable as follows

make VERBOSE=1;

The caveat of this solution is that EVERYTHING becomes verbose, so you could have too many output data.

Option 3 – Add the variable -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON to your cmake command

Adding the option -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON to the cmake command, it will enable verbosity on all generated Makefiles permanently.
So, assuming you are in the folder where you want to make the build, execute the following to generate the Makefiles:

cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON $path_to_project_source;

and then just issue make to perform the build with verbose output.
Please note, you cannot disable verbose output using make VERBOSE=0 after you enable it through cmake, you need to execute the cmake command again without the -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON option.

Bonus

To remove the ‘building’ and ‘linking’ lines from the output

e.g.

[ 10%] Building C object libs/segmentation/CMakeFiles/segments.dir/list_helpers.c.o
and
[ 30%] Linking C static library libsegments.a

add the option -DCMAKE_RULE_MESSAGES:BOOL=OFF to your cmake command to disable them.
e.g.

cmake -DCMAKE_RULE_MESSAGES:BOOL=OFF $path_to_project_source;

To remove the ‘Entering directory’ and ‘Leaving directory’ lines from the output

e.g.

make[2]: Leaving directory '/home/george/Projects/3rd Party/segments222bit/cmake-build-debug'
and
make[2]: Entering directory '/home/george/Projects/3rd Party/segments222bit/cmake-build-debug'

add the option --no-print-directory to your make command to disable them.
e.g.

make --no-print-directory;

Ubuntu server 16.04+ MySQL port is only accessible from localhost (127.0.0.1)

Recently, we got access to an Ubuntu 16.04 LTS server that had MySQL server installed on it but was not accessible to our external servers.
The service was accessible when testing from localhost but it was not when testing from any other machine.
Executing nmap from another machine would return the value 3306/tcp closed mysql   conn-refused as below.

[bytefreaks@fedora ~]$ nmap -vv -p 3306 192.168.10.11


 
 Starting Nmap 7.40 ( https://nmap.org ) at 2017-03-06 17:21 EET
 Initiating Ping Scan at 17:21
 Scanning 192.168.10.11 [2 ports]
 Completed Ping Scan at 17:21, 0.06s elapsed (1 total hosts)
 Initiating Parallel DNS resolution of 1 host. at 17:21
 Completed Parallel DNS resolution of 1 host. at 17:21, 0.00s elapsed
 Initiating Connect Scan at 17:21
 Scanning 192.168.10.11 [1 port]
 Completed Connect Scan at 17:21, 0.06s elapsed (1 total ports)
 Nmap scan report for 46.101.137.70
 Host is up, received syn-ack (0.061s latency).
 Scanned at 2017-03-06 17:21:31 EET for 1s
 PORT     STATE  SERVICE REASON
 3306/tcp closed mysql   conn-refused
 
 Read data files from: /usr/bin/../share/nmap
 Nmap done: 1 IP address (1 host up) scanned in 0.16 seconds

The problem was with the default configuration of mysqld that is found in the file /etc/mysql/mysql.conf.d/mysqld.cnf.
At line 41 we got the following snippet:

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 127.0.0.1

What the line bind-address            = 127.0.0.1 says is that, the service will only listen on localhost.
At this stage there are two solutions that you can apply using your favorite text editor (e.g. sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf):

Solution A:

Completely remove the line bind-address            = 127.0.0.1 or comment it out by adding a # in front of it as follows #bind-address            = 127.0.0.1.

Solution B:

Replace 127.0.0.1 with the IP that you want mysql service to be available to. In our case the line became bind-address            = 192.168.10.11.

After you are done with the change, you need to restart the service for the change to take place:

bytefreaks@OSUbuntu:~$ sudo /etc/init.d/mysql restart
 [ ok ] Restarting mysql (via systemctl): mysql.service.

From an external machine you can verify that the configuration was applied correctly using nmap as below:

[bytefreaks@fedora ~]$ nmap -vv -p 3306 192.168.10.11
 Starting Nmap 7.40 ( https://nmap.org ) at 2017-03-06 17:24 EET
 Initiating Ping Scan at 17:24
 Scanning 192.168.10.11 [2 ports]
 Completed Ping Scan at 17:24, 0.06s elapsed (1 total hosts)
 Initiating Parallel DNS resolution of 1 host. at 17:24
 Completed Parallel DNS resolution of 1 host. at 17:24, 0.00s elapsed
 Initiating Connect Scan at 17:24
 Scanning 192.168.10.11 [1 port]
 Discovered open port 3306/tcp on 46.101.137.70
 Completed Connect Scan at 17:24, 0.06s elapsed (1 total ports)
 Nmap scan report for 46.101.137.70
 Host is up, received syn-ack (0.061s latency).
 Scanned at 2017-03-06 17:24:30 EET for 0s
 PORT     STATE SERVICE REASON
 3306/tcp open  mysql   syn-ack
 Read data files from: /usr/bin/../share/nmap
 Nmap done: 1 IP address (1 host up) scanned in 0.16 seconds

You should get the value 3306/tcp open  mysql   syn-ack.


CentOS: prevent eth0 from starting at boot time

On a CentOS server we own, we had to disable eth0 from starting at boot time
To do so we needed to modify the file /etc/sysconfig/network-scripts/ifcfg-eth0 and set the value ONBOOT="yes" to ONBOOT="no".

Using you favorite text editor, make this change and restart your machine to verify that the change was successful.

Below is the sample content of /etc/sysconfig/network-scripts/ifcfg-eth0 after the change was applied to prevent eth0 from starting at boot time.

  GNU nano 2.3.1                File: /etc/sysconfig/network-scripts/ifcfg-eth0                             Modified

TYPE="Ethernet"
 BOOTPROTO=dhcp
 DEFROUTE="yes"
 IPV4_FAILURE_FATAL="no"
 IPV6INIT="yes"
 IPV6_AUTOCONF="yes"
 IPV6_DEFROUTE="yes"
 IPV6_FAILURE_FATAL="no"
 NAME="eth0"
 UUID="792d6842-221d-5c99-ba98-cddbba4ff263"
 ONBOOT="no"
 HWADDR="00:AA:5D:01:22:2B"
 DNS1="10.15.10.5"
 DOMAIN="bytefreaks.local"
 IPADDR=10.15.10.249
 PREFIX=24
 GATEWAY=10.15.10.1
 PEERDNS=yes
 PEERROUTES=yes
 IPV6_PEERDNS=yes
 IPV6_PEERROUTES=yes

How to use git features on a local project without a Git server

Like many of you, sometimes we develop code that does not belong to a Git server.
Working as so, one would think that we would miss all the features of a Version Control System (VCS).
Fortunately, this assumption is wrong.
Using the already installed Git tools, we can create a new local repository in any system folder with no additional configuration.

To do so, and create a new repository from an existing project, we need to do the following using a terminal/shell:

  1. Navigate into the directory that contains the project e.g. cd /home/bytefreaks/Projects/Party/banana/
  2. Type git init
    This command will create an empty Git repository in that folder and it will produce a message as follows:
    Initialized empty Git repository in /home/bytefreaks/Projects/Party/banana/.git/
  3. In case you have files that should not be included in your repository, it is better that you create a .gitignore file and add them there.
    This way you will be able to indicate all of the files that you don’t want to the repository to track.
  4. Use git add . (please note that you need the dot . for this command)
    This command will stage all files that are not in .gitignore to be part of your next commit.
  5. Finally, type git commit or git commit -m "Initial Commit with status bla bla", to make your first commit to the repository
  6. Profit!

By now, you should have a fully functional local git repository without the assistance of an external server.